Change filter value before executing SQL

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.

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

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

Let me know.

1 Like

Thanks a lot. That does the job :slight_smile:

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?

Hey @bef :wave: according to the Default routes - Documentation you must override this route:

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

Let me know.


Thanks for the hint. That was the missing link.