In our project we have 3 databases and I wanted to pool 2 tables that are in different databases. For that I tried to create a workspace in which I have my Contract and Beneficiaries collection, in which I try to display all the Beneficiaries having their id in the Contract collection which has the field fkBeneficiaryId
Ok then a solution (only if you have 1 to 1 relationship) would be to create a smart field (cf. the documentation on the beneficiary collection with the id of the benefiacyās contract.
Then you will have a new column and you will be able to filter on it for records without value on this column.
For a persistant filter you can create segment with this solution.
Hi,
I managed to create the new column but when I try to create a segment I canāt see the new column.
And also these 2 collections are in 2 different databases and in my opinion thatās why I canāt see the data.
In order to filter your smart field, you must 1) add the isFilterable to true in your agent for this field.
2) Implement the filter function for the field
However when I try to put is blank or is present I get the following error
[forest] ļ³ļ³ļ³ Unexpected error: āfilterā method on smart field ānvContractsā must return a
condition
{
āstackā: āError: "filter" method on smart field "nvContracts" must return a condition\n
at _callee$ (/usr/src/app/node_modules/forest-express/dist/services/base-filters-parser.js:98:19)\n at tryCatch (/usr/src/app/node_modules/rege
nerator-runtime/runtime.js:64:40)\n at Generator.invoke (/usr/src/app/node_modules/regenerator-runtime/runtime.js:299:22)\n at Generator.next (/
usr/src/app/node_modules/regenerator-runtime/runtime.js:124:21)\n at asyncGeneratorStep (/usr/src/app/node_modules/forest-express/node_modules/@bab
el/runtime/helpers/asyncToGenerator.js:3:24)\n at _next (/usr/src/app/node_modules/forest-express/node_modules/@babel/runtime/helpers/asyncToGenera
tor.js:25:9)ā
}
Iām trying to catch up, sorry if Iām repeating . So to summarize, your ānvContractsā is on your āBeneficiariesā collection.
My suggestion, nvContracts should actually be a smart relationships. This will allow you to your contract inside a benificiary and easily filter on it.
So it should give something like that:
{
field: 'nvContracts',
type: 'String',
// In reference put the name of your contracts collection and it's primary key ("tableName.primaryKey")
reference: 'Contracts.id',
isFilterable: true,
get: async (record) => {
return await models.nvContracts.findOne({
where: {
fkUserId: record.dataValues.fkUserIdKey
}
})
},
filter({ condition, where }) {
const [,nvContractField] = condition.field.split(':');
const nvContracts = await models.nvContracts.findAll({
attributes: ['fkUserId'],
where: { [nvContractField]: where },
});
return nvContracts.map(contract => contract.fkUserId);
}
}