EagerLoading doesn't work on helpers


EagerLoading doesn’t work on helpers methods
This one works fine:

await user.query()
        .where('enabled', 1)
        .orderBy('some_time_column', 'DESC')

But when I try with helpers such (first() ) it won’t work:

await user.query()
        .where('enabled', 1)
        .orderBy('some_time_column', 'DESC')

With the first query I get back the “Posts” object, but the second does not return “Posts”.

I don’t really care using the fetch method, just wanted to know if it should behave like this?



Hi, could you try the following

await User.query().where('enabled', 1).with('Posts').orderBy('column', desc).find(params.id)

Best Regards


Hi IngPaz

But if I don’t have the “id” of the user?
Or if it’s not even a users table but something else…


you can pass the id of the table your querying


I understand, but I’ve asked on case which I don’t have the id of the row.
Only some parameters like “enabled” and orderby date.
In that case “find()” won’t help me.


How do you check the existence of posts?


Hi Virk,

There could be a case where there’s no posts related to user
well in that case the post will return empty array