Smart fields filters

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 ?

Hi @JeremyV :wave: sorry for the late response.
Unfortunately it’s not doable easily yet :confused: I push your request to our product board.
I try this morning to find a not ugly workaround without success.
I suggest you to do something like:

filter: async ({ condition }) => {
  const gestionnaire = condition.value;

  // find all the `resourceIds` from `roles` who validate the `gestionnaire`
  const resourceIds = await models.roles.findOne({
    attributes: [resource_id],
    where: {
      name: 'coowner_manager',
      resource_type: 'Place',
    },
    include: [{
      model: models.identities,
      as: 'identitiesThroughIdentitiesRoles'
      where: {
        // here you need to transform `gestionnaire` var into sql where clause
      }
    }]
  })

  return { id: resourceIds };
}

Let me know if that help.