System Information
- Strapi Version: 3.2.5
- Operating System: Windows 10
- Database: MongoDB
- Node Version: 12.18.2
- NPM Version: 6.14.5
- Yarn Version: 1.22.4
Good day, I’m trying to use beforeFind
to search using a calculated value from afterFind
, this is the kind of condition I’m trying to work under and would like any suggestions on how I can accomplish this
I’m using lifecycle methods as I want this functionality from the admin panel
I have the following two models:
TypeOuter = {
OuterData: string,
InnerData: TypeInner,
InnerDataName: string // populated from afterFind from TypeInner
}
TypeInner = {
Name: string
}
During my afterFind
method I do something like this:
afterFind: async (results, params, populate) => {
if (results && results.length > 0)
results.forEach(r => r.InnerDataName= r.InnerData.Name)
}
Now, from the admin panel, I would like to be able to search based on the InnerDataName, when submitting the search I have the following that’s sent to beforeFind
:
params: {
_limit: '10',
_sort: 'Name:ASC',
InnerDataName: 'Something',
_start: '0',
_where: [ {} ]
},
populate: undefined
What’s a possible way that I can go about searching by the InnerDataName and still get the data? I’m not too clear on the beforeFind
usage at al
Note that searching by this field doesn’t work as it’s only calculated during the
afterFind
, I can potentially move this tobeforeFind
as long as it retains the calculated field. The reason I’ve got theInnerDataName
showing is because it’s a separate relationship/object but for the purpose of the search page on the admin panel it’s kind of necessary that the user can at least see theInnerDataName
Any advice/recommendations would be appreciated