Hi, I am trying to get the most out of filtering smart fields.
I have been reading the documentation and this topic
But I still can’t figure out how I can achieve filtering on my fields.
Here’s my smart field :
field: 'gestionnaire',
type: 'String',
isFilterable: true,
get: place => models.roles.findOne({
where: {
name: 'coowner_manager',
resource_type: 'Place',
resource_id: place.id
},
include: [{
model: models.identities,
as: 'identitiesThroughIdentitiesRoles'
}]
}).then(role => `${role ? role.identitiesThroughIdentitiesRoles[0].firstName : ''} ${role ? role.identitiesThroughIdentitiesRoles[0].lastName.toUpperCase() : ''}`)
In the filter method, I feel the need to gather my “role” again as so :
const role = await models.roles.findOne({
where: {
name: 'coowner_manager',
resource_type: 'Place',
resource_id: place.id
},
include: [{
model: models.identities,
as: 'identitiesThroughIdentitiesRoles'
}]
});
But here I don’t have my “place” anymore - i.e. I don’t have access to my record ID.
You should also know that there is no direct relationship between Places
and Roles
, Roles is a polymorphic table so I have to manually query by specifying from which table I’m coming from (resource_type: 'Place'
).
Is it doable ? What am I missing ?