开发者

users collection1 minus users collection2

I am using Rails 3.0.8

Lets say that I have two collections of users.

users1 = User.where(....)
users2 = User.where(....)

I need

users1 - users2

One way to get the solution is

ids开发者_如何学编程 = users1.map(&:id) - users2.map(&:id)
ids.map{ |i| User.find(i) }

Above code will work. However I was wondering if ActiveRecord implements some kind of equality operator so that I do not have to get ids from that collection.


users1 - users2 works perfectly, keep it simple!

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜