开发者

Multi conditions in Mongoid

I have Thing model which has an array of topics and followings.

I want to find all things that the current_user following its Topic or its 'User'.

@things = Thing
          .where(:user_id.in => current_user.following.map{ |u| u._id })
          .where(:topic_id.in => current_user.topics.map{ |u| u开发者_如何学编程._id })

something like this. But this actually not working. it just returns records that common things between the both where conditions.

What I want is to return all the records that 2 where statements find.

Thanks


.any_of(
  { :user_id.in => current_user.following.map{ |u| u._id } }, 
  { :topic_id.in => current_user.topics.map{ |u| u._id } }
)


it will be good to set the relations

references_one :user, :topic

and rely on smth like

where :user.in => current_user.following, :topic.in =>current_user.topics...
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜