# Smart Relationship with Smart collection - isFilterable not working

**URL:** <https://community.forestadmin.com/t/smart-relationship-with-smart-collection-isfilterable-not-working/7010>\
**Category:** Help me!\
**Created:** [January 29, 2024, 10:44am UTC](https://community.forestadmin.com/t/smart-relationship-with-smart-collection-isfilterable-not-working/7010 "2024-01-29T10:44:16Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Soufiane](https://avatars.discourse-cdn.com/v4/letter/s/8edcca/32.png) [@Soufiane](https://community.forestadmin.com/u/Soufiane)\
**Post date:** [January 29, 2024, 10:44am UTC](https://community.forestadmin.com/t/smart-relationship-with-smart-collection-isfilterable-not-working/7010/1 "2024-01-29T10:44:16Z")

</div>

The fields "mandatory"`Preformatted text` not work , in my smart collection

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/1/1d86f9e0640364354c8fcf0a0823f721b8124069.png)

Project name: .Sergic  
Team name: gestion  
Environment name: Développement  
Agent (forest package) name & version: 9  
Database type: Postgres  
Recent changes made on your end if any: upgrade to v9

---

<div class="post-metadata">

**Author:** ![GuillaumeGautreau](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/guillaumegautreau/32/557_2.png) [@GuillaumeGautreau](https://community.forestadmin.com/u/GuillaumeGautreau)\
**Post date:** [January 29, 2024, 12:23pm UTC](https://community.forestadmin.com/t/smart-relationship-with-smart-collection-isfilterable-not-working/7010/2 "2024-01-29T12:23:36Z")

</div>

Hello Soufiane,

Could you please tell us more about the configuration of your smart collection?

Filters on smart collections need to be handled by your code, because they don’t directly rely on sequelize like other collections.

So my assumption here is that this particular filter is not correctly handled by the customization code that is present on your project to list records.

---

<div class="post-metadata">

**Author:** ![Soufiane](https://avatars.discourse-cdn.com/v4/letter/s/8edcca/32.png) [@Soufiane](https://community.forestadmin.com/u/Soufiane)\
**Post date:** [January 29, 2024, 12:47pm UTC](https://community.forestadmin.com/t/smart-relationship-with-smart-collection-isfilterable-not-working/7010/3 "2024-01-29T12:47:22Z")

</div>

```javascript
collection('missingContractCategories', {
    isSearchable: true,
  actions: [],
  fields: [
    {
    field: 'id',
    type: 'String'
  },{
    field: 'placeReference',
    type: 'String',
     isFilterable: true
  }, {
    field: 'display_name',
    type: 'String',
    isFilterable: true,
   
  }, {
    field: 'mandatory',
    type: 'Boolean',
    isFilterable: true,
   // isSortable: true,
    
      // filter: async ({ condition, where }) => {
      // const positive = condition.operator === 'equal' && !!condition.value || condition.operator === 'not_equal' && !condition.value
      // console.log("🚀 ~ file: missing-contract-categories.js:35 ~ filter: ~ positive:", positive)
      // return { mandatory: positive };
      // }
    
    }, {
    field: 'state',
    isFilterable: true,
    // type: 'String',
      type: 'Enum',
     enums: ['active',
        'canceled',
        'pending_cancellation',
        'pending',
        'completed',
        'archived'
      ],
      isFilterable: true,
    },

```

```javascript
router.get('/missingContractCategories', permissionMiddlewareCreator.list(), (request, response, next) => {
  
  const recordSerializer = new RecordSerializer({ name: 'missingContractCategories' });

  // Get query parameters information
  const pageSize = Number(request.query.page.size) || 20;
  const page = Number(request.query.page.number) || 1;
  const from = (page - 1) * pageSize;
  const to = from + pageSize;
  //let search = request.query.search;
  let sort = request.query.sort;
  let filters;
  try {
    filters = request.query?.filters && JSON.parse(request.query.filters);
    console.log("🚀 ~ file: missing-contract-categories.js:25 ~ router.get ~ request.query?.filters:", request.query?.filters)
  } catch (e) {
    filters = undefined;
  }
  //console.log("🚀 ~ file: missing-contract-categories.js ~ line 33 ~ router.get ~ filters", filters)
  axios.get(
    `${API_URL}/forest_admin/missing_categories`, {
    headers: {
      'Authorization': `Bearer ${process.env.ACCESS_TOKEN}`,
      'X-CURRENT-USER-EMAIL': request.user.email
    }
  }).then(async res => {
    const dataToSend = [];
    res.data.map(item => {
      const placeReference = item.sergic_id_full;
      item.missing_categories.map(categorie => { 
        const cat = {
          id: `${item.id}-${categorie.id}`,
          placeReference: placeReference,
          display_name: categorie.display_name,
          mandatory: categorie.mandatory,
          state: categorie.last_maintenance_contract ? categorie.last_maintenance_contract.state : '' ,
          reference: categorie.last_maintenance_contract ? categorie.last_maintenance_contract.reference : '',
          end_date: categorie.last_maintenance_contract ? categorie.last_maintenance_contract.end_date : null,
          origin_date: categorie.last_maintenance_contract ? categorie.last_maintenance_contract .origin_date : null,
          amount: categorie.last_maintenance_contract ? categorie.last_maintenance_contract.amount: '',
          repartition_key_id: categorie.last_maintenance_contract ? categorie.last_maintenance_contract.repartition_key_id: '',
          automatic_renewal: categorie.last_maintenance_contract ? categorie.last_maintenance_contract.automatic_renewal : '',
          notice_in_month: categorie.last_maintenance_contract ? categorie.last_maintenance_contract.notice_in_month: ''

        };
         dataToSend.push(cat);

      });
    });
     
    response.send({

      ...(await recordSerializer.serialize(dataToSend.slice(from, to))),
      meta: { count: dataToSend.length }
    });
  }).catch(err => {
    if (err.response?.data?.error?.message) {
      response.status(400).send(err.response.data.error.message);
    } else {
      response.status(400).send('Erreur inattendue, veuillez contacter votre administrateur.');
    }
  });
});

```

---

<div class="post-metadata">

**Author:** ![GuillaumeGautreau](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/guillaumegautreau/32/557_2.png) [@GuillaumeGautreau](https://community.forestadmin.com/u/GuillaumeGautreau)\
**Post date:** [January 29, 2024, 1:59pm UTC](https://community.forestadmin.com/t/smart-relationship-with-smart-collection-isfilterable-not-working/7010/4 "2024-01-29T13:59:16Z")

</div>

Thanks for sharing the code.

It seems that this code contains the beginning of a support for filter. If you want filters to work on the frontend, the logic has to be implemented in your route handler, the same way it is done for search.

The query parameter `filter` contains the JSON representation of a filter:

```js
// If there is only 1 filter, the filter is an object such as:
{
  "field":"mandatory",
  // Supported operators depend on the field's type
  "operator":"equal",
  "value":"true"
}

// If there are multiple filters, it contains a representation
// of an aggregation of filters
{
  // Can be "and" or "or"
  "aggregator":"and",
  "conditions":[
    {"field":"mandatory","operator":"equal","value":"bar"}, 
    {"field":"foo","operator":"equal","value":"bar"}
  ]
}

```

The frontend only allows to select one level of aggregations.

---

<div class="post-metadata">

**Author:** ![Soufiane](https://avatars.discourse-cdn.com/v4/letter/s/8edcca/32.png) [@Soufiane](https://community.forestadmin.com/u/Soufiane)\
**Post date:** [February 1, 2024, 9:08am UTC](https://community.forestadmin.com/t/smart-relationship-with-smart-collection-isfilterable-not-working/7010/5 "2024-02-01T09:08:22Z")

</div>

Thank you for your feedback, The filter still doesn’t work; it is normal that field “mandatory” in forestadmin-shema.json , “isFilterable” is false ?

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/9/962f6bb03b191bcaf2c0829eb4773ed7b36769a3.png)

---

<div class="post-metadata">

**Author:** ![GuillaumeGautreau](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/guillaumegautreau/32/557_2.png) [@GuillaumeGautreau](https://community.forestadmin.com/u/GuillaumeGautreau)\
**Post date:** [February 1, 2024, 1:10pm UTC](https://community.forestadmin.com/t/smart-relationship-with-smart-collection-isfilterable-not-working/7010/6 "2024-02-01T13:10:03Z")

</div>

I’ve made the test locally, by just setting `isFilterable` on a field, it correctly switches the value in the schema.

If it’s not the case on your side, could you please check the value of `NODE_ENV` on your agent? If the value is set to `production`, the schema is not generated at startup.

It seems that there is a bug on our side though, because activating the value of `isFilterable` does not change the behavior on the app. I’m investigating this problem.

---

<div class="post-metadata">

**Author:** ![Soufiane](https://avatars.discourse-cdn.com/v4/letter/s/8edcca/32.png) [@Soufiane](https://community.forestadmin.com/u/Soufiane)\
**Post date:** [February 1, 2024, 1:15pm UTC](https://community.forestadmin.com/t/smart-relationship-with-smart-collection-isfilterable-not-working/7010/7 "2024-02-01T13:15:41Z")

</div>

scripts": {  
“dev”: “SET NODE\_ENV=development&& nodemon ./server.js”,  
“staging”: “NODE\_ENV=staging node ./server.js”,  
“prod”: “NODE\_ENV=production node ./server.js”  
}

---

<div class="post-metadata">

**Author:** ![GuillaumeGautreau](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/guillaumegautreau/32/557_2.png) [@GuillaumeGautreau](https://community.forestadmin.com/u/GuillaumeGautreau)\
**Post date:** [February 1, 2024, 1:20pm UTC](https://community.forestadmin.com/t/smart-relationship-with-smart-collection-isfilterable-not-working/7010/8 "2024-02-01T13:20:55Z")

</div>

If you launch the script `dev`, does it correctly generates the schema?

---

<div class="post-metadata">

**Author:** ![Soufiane](https://avatars.discourse-cdn.com/v4/letter/s/8edcca/32.png) [@Soufiane](https://community.forestadmin.com/u/Soufiane)\
**Post date:** [February 1, 2024, 1:31pm UTC](https://community.forestadmin.com/t/smart-relationship-with-smart-collection-isfilterable-not-working/7010/9 "2024-02-01T13:31:16Z")

</div>

No, the shema is not correctly generated

---

<div class="post-metadata">

**Author:** ![Soufiane](https://avatars.discourse-cdn.com/v4/letter/s/8edcca/32.png) [@Soufiane](https://community.forestadmin.com/u/Soufiane)\
**Post date:** [February 1, 2024, 1:42pm UTC](https://community.forestadmin.com/t/smart-relationship-with-smart-collection-isfilterable-not-working/7010/10 "2024-02-01T13:42:01Z")

</div>

yndic-one\> nodemon ./server.js  
[nodemon] 2.0.20  
[nodemon] to restart at any time, enter `rs`  
[nodemon] watching path(s): _._  
[nodemon] watching extensions: js,mjs,json  
[nodemon] starting `node ./server.js`  
No env file present for the current environment: undefined  
Falling back to .env config  
┌───────────────────────────────────┐  
│ New version of nodemon available! │  
│ Current Version: 2.0.20 │  
│ Latest Version: 3.0.3 │  
└───────────────────────────────────┘

---

<div class="post-metadata">

**Author:** ![GuillaumeGautreau](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/guillaumegautreau/32/557_2.png) [@GuillaumeGautreau](https://community.forestadmin.com/u/GuillaumeGautreau)\
**Post date:** [February 1, 2024, 2:01pm UTC](https://community.forestadmin.com/t/smart-relationship-with-smart-collection-isfilterable-not-working/7010/11 "2024-02-01T14:01:55Z")

</div>

Is the value of `NODE_ENV` set in your `.env` file?

Can you console.log the value of `process.env.NODE_ENV` in your `server.js` file?

I can see from your command line that you start your server with `nodemon ./server.js` whereas you should start it with `npm run dev` or `yarn dev` in order to correctly set environment variables before running the server.

---

<div class="post-metadata">

**Author:** ![Soufiane](https://avatars.discourse-cdn.com/v4/letter/s/8edcca/32.png) [@Soufiane](https://community.forestadmin.com/u/Soufiane)\
**Post date:** [February 1, 2024, 2:22pm UTC](https://community.forestadmin.com/t/smart-relationship-with-smart-collection-isfilterable-not-working/7010/12 "2024-02-01T14:22:06Z")

</div>

🚀 ~ process.env.NODE\_ENV: development in server.js file

.env.development: development  
.env.staging: staging  
.env.production: production

---

<div class="post-metadata">

**Author:** ![GuillaumeGautreau](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/guillaumegautreau/32/557_2.png) [@GuillaumeGautreau](https://community.forestadmin.com/u/GuillaumeGautreau)\
**Post date:** [February 1, 2024, 2:41pm UTC](https://community.forestadmin.com/t/smart-relationship-with-smart-collection-isfilterable-not-working/7010/13 "2024-02-01T14:41:55Z")

</div>

Ok, weird. Can you share me the lines of logs that are written in the console when starting your agent?

Forest Admin’s code should logs some lines indicating what is done regarding the schema (if it’s generated, if it is sent to our servers).

---

<div class="post-metadata">

**Author:** ![Soufiane](https://avatars.discourse-cdn.com/v4/letter/s/8edcca/32.png) [@Soufiane](https://community.forestadmin.com/u/Soufiane)\
**Post date:** [February 1, 2024, 2:46pm UTC](https://community.forestadmin.com/t/smart-relationship-with-smart-collection-isfilterable-not-working/7010/14 "2024-02-01T14:46:18Z")

</div>

\syndic-one-rebirth\> npm run dev

> syndic-one-rebirth@0.0.1 dev  
> SET NODE\_ENV=development&& nodemon ./server.js

[nodemon] 2.0.15  
[nodemon] to restart at any time, enter `rs`  
[nodemon] watching path(s): _._  
[nodemon] watching extensions: js,mjs,json  
[nodemon] starting `node ./server.js`  
Your application is listening on port 3310.  
[forest] 🌳🌳🌳 Checking need for apimap update…

---

<div class="post-metadata">

**Author:** ![GuillaumeGautreau](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/guillaumegautreau/32/557_2.png) [@GuillaumeGautreau](https://community.forestadmin.com/u/GuillaumeGautreau)\
**Post date:** [February 1, 2024, 2:49pm UTC](https://community.forestadmin.com/t/smart-relationship-with-smart-collection-isfilterable-not-working/7010/15 "2024-02-01T14:49:36Z")

</div>

> [@Soufiane](#):
>
> Checking need for apimap update

Don’t you have anything after this line?

---

<div class="post-metadata">

**Author:** ![Soufiane](https://avatars.discourse-cdn.com/v4/letter/s/8edcca/32.png) [@Soufiane](https://community.forestadmin.com/u/Soufiane)\
**Post date:** [February 1, 2024, 2:50pm UTC](https://community.forestadmin.com/t/smart-relationship-with-smart-collection-isfilterable-not-working/7010/16 "2024-02-01T14:50:47Z")

</div>

Your admin panel is available here: [https://app.forestadmin.com/Sergic/Dev/Gestion](https://app.forestadmin.com/Sergic/Dev/Gestion)  
[forest] 🌳🌳🌳 No change in apimap, nothing sent to Forest.

---

<div class="post-metadata">

**Author:** ![GuillaumeGautreau](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/guillaumegautreau/32/557_2.png) [@GuillaumeGautreau](https://community.forestadmin.com/u/GuillaumeGautreau)\
**Post date:** [February 1, 2024, 3:41pm UTC](https://community.forestadmin.com/t/smart-relationship-with-smart-collection-isfilterable-not-working/7010/17 "2024-02-01T15:41:07Z")

</div>

Ok, if I take a look at what we have on our side, I can see that `isFilterable` is correctly set to `true` on your schema for the field `mandatory` in the collection `missingContractCategories`.

You have another field named `mandatory` in the collection `categories` (first to come in the schema), with `isFilterable = false`.

So I would say that the schema is correctly updating on your side.

Now the remaining issue comes from our side, with the filters not being correctly displayed when changing the property `isFilterable` on fields. A fix is on its way.

After the release of the fix, you’ll have to set `isFilterable: false` in your field’s declaration, start the server for the schema to be sent, then switch back the value to `true` and start the server again.

---

<div class="post-metadata">

**Author:** ![Soufiane](https://avatars.discourse-cdn.com/v4/letter/s/8edcca/32.png) [@Soufiane](https://community.forestadmin.com/u/Soufiane)\
**Post date:** [February 1, 2024, 4:04pm UTC](https://community.forestadmin.com/t/smart-relationship-with-smart-collection-isfilterable-not-working/7010/18 "2024-02-01T16:04:58Z")

</div>

Thanks, when is the release of the fix ?

---

<div class="post-metadata">

**Author:** ![GuillaumeGautreau](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/guillaumegautreau/32/557_2.png) [@GuillaumeGautreau](https://community.forestadmin.com/u/GuillaumeGautreau)\
**Post date:** [February 1, 2024, 4:17pm UTC](https://community.forestadmin.com/t/smart-relationship-with-smart-collection-isfilterable-not-working/7010/19 "2024-02-01T16:17:13Z")

</div>

We’re working on the fix, sorry for the delay.

In the meantime, I think you can apply a workaround to fix this issue:

1. Comment the whole declaration of the field `mandatory`
2. Start your server to send the schema, then stop your server
3. Add this field back in your collection
4. Start your server again.

It should do the trick, unblock you and give us some time to release and correctly test the fix.

Let me know if it works for you.

---

<div class="post-metadata">

**Author:** ![GuillaumeGautreau](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/guillaumegautreau/32/557_2.png) [@GuillaumeGautreau](https://community.forestadmin.com/u/GuillaumeGautreau)\
**Post date:** [February 1, 2024, 4:37pm UTC](https://community.forestadmin.com/t/smart-relationship-with-smart-collection-isfilterable-not-working/7010/20 "2024-02-01T16:37:43Z")

</div>

The fix is now live.

Make sure to make at least one modification that will change the schema, this way the schema will be sent again and the property `isFilterable` will be correctly be updated in your app.

[Next page](https://community.forestadmin.com/t/smart-relationship-with-smart-collection-isfilterable-not-working/7010.md?page=2)
