Given the following models:
User (id)
has_many :groups
has_many :communities
Groups (community_id (OPTIONAL) )
belongs_to :user
belongs_to :community
Communities (id, archived (boolean) )
has_many :groups
has_many :group_members, :include => :user
I can easily get a user’s groups by doing:
current_user.groups
The problem is if a community is archived, I don’t want that returned in the current_user.groups.
How can I get all of a user’s groups where the community is not archived?
Thanks
current_user.groups.joins(:community).where('communities.archived' => false)