Rails - How to use active record to query with a nested condition? -
lets have 3 models
user(id, guest(boolean)) belongs_to :room_user room (id) roomuser (id, room_id, user_id) has_many :users
right can do, room.room_users , associated users in room. that's doable rails.
what want room.room_users_active
so in room model have:
def room_users_active self.room_users.where(:......) end
the challenge here want condition reach user table. , following:
return room_users user not guest (user.guest == false).
ideas? thanks
not tested, should work, try , let me know
def room_users_active room_users.joins(:users).where('user.guest = false') end
fixed wrong method call see here
Comments
Post a Comment