Lifecycle hooks not called on populated collections?

System Information
  • Strapi Version: 4.1.12
  • Operating System: Ubuntu
  • Database: PostgreSQL
  • Node Version: 16
  • NPM Version: 8
  • Yarn Version:

I have created two lifecycle hooks in collection X. On afterFindOne and afterFindMany it checks to see if a specific field has a value and if not setting it to a default value.

I have another collection Y. It has a one-to-many relationship with X.

When I i call /api/Xs/1 The field is properly filled with the default value. “x.attributes.field” == Default Value

However, when I call /api/Ys/1?populate=* it is not. “y.attributes.x.data.attributes.field” == null

Am I missing something here or is this just the way it is supposed to be? Is lifecyclehooks not being called on populated relation collections?


tbh Strapi seems to want us to not use lifecycleHooks like they would made our life easier.
Limiting the data we can use inside lifecycleHooks and changing their behaviour undocumented from version to version made us - as team - decide to not using lifecycleHooks at all and write our own logic that gets called before saving/updating an entity.

So tldr to your question: Maybe this is supposed to be like that. Before (in v3) it was possible to do it like you assumed.

Thank you. Can you possibly point me to the proper way of doing what I want?

is there any solution? I got struck by this. I want to populate the relational field in afterFindOne lifecycle