Lifecycle event to hook relation in the "with" method
When I use the with method, ex:
const users = await User.query().with('posts').fetch()
I don't have an event to listen the fetchAll and modify the relation data using eager loading.
When you use query builder, Lucid doesn't have any data about that row. That's why it's not triggering any lifecycle hook.
What you need to do (not recommended) is to select a row first.
const users = await User.all();
for (let user of users) {
cont posts = await user.posts();
user.$sideLoaded.posts = posts
}
Ok @sorxrob. But we have the n + 1 problem, not recomended in the documentation.

Ok @sorxrob. But we have the n + 1 problem, not recomended in the documentation.
Yes that will be the problem. There's no way currently to listen to an event via lifecycles with query builder.
May I be suggesting this functionality here?
I guess you can
Hey there! 👋
Please, create a proper RFC using our template so we can better understand your needs and what should be done.