I'm trying to load a nested association, a User
can belong to many Groups
and I want to load all Posts
from Groups
where the user is a member, but only the posts no the groups as well.
Something like current_user.groups.eager_load(:posts)
, but without nesting posts under groups.
I'm assuming Post
belongs to Group
here.
Start with the model that you need to load and build the query from there. If user belongs to 2 groups here, this will load all the posts from those 2 groups.
Post.where(group: current_user.groups)
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments