开发者

How to query across a nested resource with a condition

I have the following models:

User (id)
UserRoom (user_id, room_id, banned(boolean)
Room (id, uuid)

Right now I can get all of a user's rooms as follows:

current_user.rooms.find_all_by_uuid(@requested_ids)

What I would like to do is expand this to only s开发者_StackOverflow中文版how rooms that aren't banned (banned => false).

What's the right rails way to add that condition to the query?

Thanks


Try using conditions like so:

current_user.rooms.find :all, :conditions => { :uuid => @requested_id, :banned => false }

Using @requested_ids as an array (probably not as elegant):

current_user.rooms.find :all, :conditions => ["uuid IN (?) AND banned=0", @requested_ids]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜