# Smart fields filters

**URL:** <https://community.forestadmin.com/t/smart-fields-filters/3484>\
**Category:** Help me!\
**Created:** [October 7, 2021, 3:31pm UTC](https://community.forestadmin.com/t/smart-fields-filters/3484 "2021-10-07T15:31:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![JeremyV](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/jeremyv/32/1033_2.png) [@JeremyV](https://community.forestadmin.com/u/JeremyV)\
**Post date:** [October 7, 2021, 3:31pm UTC](https://community.forestadmin.com/t/smart-fields-filters/3484/1 "2021-10-07T15:31:05Z")

</div>

Hi, I am trying to get the most out of filtering smart fields.

I have been reading the [documentation](https://docs.forestadmin.com/documentation/reference-guide/fields/create-and-manage-smart-fields#filtering) and this [topic](https://community.forestadmin.com/t/smart-field-filtering-on-related-data/2230)  
But I still can’t figure out how I can achieve filtering on my fields.

Here’s my smart field :

```javascript
    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 :

```javascript
       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 ?

---

<div class="post-metadata">

**Author:** ![Arnaud\_Moncel](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/arnaud_moncel/32/24_2.png) [@Arnaud\_Moncel](https://community.forestadmin.com/u/Arnaud_Moncel)\
**Post date:** [October 8, 2021, 9:55am UTC](https://community.forestadmin.com/t/smart-fields-filters/3484/2 "2021-10-08T09:55:41Z")

</div>

Hi @JeremyV 👋 sorry for the late response.  
Unfortunately it’s not doable easily yet 😕 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:

```javascript
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.
