# Change filter value before executing SQL

**URL:** <https://community.forestadmin.com/t/change-filter-value-before-executing-sql/3700>\
**Category:** Help me!\
**Created:** [November 10, 2021, 3:11pm UTC](https://community.forestadmin.com/t/change-filter-value-before-executing-sql/3700 "2021-11-10T15:11:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![bef](https://avatars.discourse-cdn.com/v4/letter/b/22d042/32.png) [@bef](https://community.forestadmin.com/u/bef)\
**Post date:** [November 10, 2021, 3:11pm UTC](https://community.forestadmin.com/t/change-filter-value-before-executing-sql/3700/1 "2021-11-10T15:11:16Z")

</div>

Hi,  
is it possible to modify a filter value before the SQL is executed.  
For example if a model has a string field, the user can select the field in the filter view and enter a string value. I want to change that string value, so that the new one is used in the SQL query.

Is there a hook, would it be possible to solve this via custom datatype or is there another solution?

Thanks in advance.

---

<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:** [November 10, 2021, 3:27pm UTC](https://community.forestadmin.com/t/change-filter-value-before-executing-sql/3700/2 "2021-11-10T15:27:01Z")

</div>

Hi @bef 👋 To achieve your goal you can do something like this in the `routes/your-collection.js` file

```javascript
// Get a list of YourCollection
router.get('/your-collection', permissionMiddlewareCreator.list(), (request, response, next) => {
  // see request.query.filters
  next();
});

```

Let me know.

---

<div class="post-metadata">

**Author:** ![bef](https://avatars.discourse-cdn.com/v4/letter/b/22d042/32.png) [@bef](https://community.forestadmin.com/u/bef)\
**Post date:** [November 11, 2021, 7:11am UTC](https://community.forestadmin.com/t/change-filter-value-before-executing-sql/3700/3 "2021-11-11T07:11:22Z")

</div>

Thanks a lot. That does the job 🙂

---

<div class="post-metadata">

**Author:** ![bef](https://avatars.discourse-cdn.com/v4/letter/b/22d042/32.png) [@bef](https://community.forestadmin.com/u/bef)\
**Post date:** [November 17, 2021, 8:14am UTC](https://community.forestadmin.com/t/change-filter-value-before-executing-sql/3700/4 "2021-11-17T08:14:18Z")

</div>

Hi, I have a follow up question to this one.  
changing the `request.query.filters` works fine for the collection filter.  
The problem is it seems not to work for related data.

Let’s say I have a parent-collection which has a relation to child-collection. I can navigate to the child-collection via “Related Data” in the parent-collection view.  
But when I enter a filter there, the GET route of child-collection is not called (where I do my query changes). That means the filter mechanisms seems to work differently there.

Am I missing something, or is there another route I have to change?

---

<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:** [November 19, 2021, 8:54am UTC](https://community.forestadmin.com/t/change-filter-value-before-executing-sql/3700/5 "2021-11-19T08:54:59Z")

</div>

Hey @bef 👋 according to the [Default routes - Documentation](https://docs.forestadmin.com/documentation/reference-guide/routes/default-routes#other-available-routes) you must override this route:

**GET** /forest/{modelName}/{id}/relationships/{hasManyRelationName}

Let me know.

---

<div class="post-metadata">

**Author:** ![bef](https://avatars.discourse-cdn.com/v4/letter/b/22d042/32.png) [@bef](https://community.forestadmin.com/u/bef)\
**Post date:** [November 19, 2021, 10:07am UTC](https://community.forestadmin.com/t/change-filter-value-before-executing-sql/3700/6 "2021-11-19T10:07:55Z")

</div>

Thanks for the hint. That was the missing link.
