Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Perceived regression in the intersection of ActiveRecord::Relations #6257

iamvery opened this Issue May 10, 2012 · 4 comments


None yet
3 participants

iamvery commented May 10, 2012

Observed in Rails 3.0.11:

(ModelA.scoped & ModelB.scoped).class
=> ActiveRecord::Relation

Observed in Rails 3.2.3:

(ModelA.scoped & ModelB.scoped).class
=> Array

There was a particular circumstance that I easily overcame by using a where instead of the set intersection, but I wanted to raise the issue in case this was unintentional. I spent some time trying to locate some documentation about the change and was unable to find any. Unfortunately, I'm not familiar enough with the Rails / AR code to know how to even find the implementation for set intersection. (Maybe its part of Arel?) Anyway, its pretty tough searching for "&" in code :P


I wonder if this is not just loading the target and returning the objects, which would give you [].class => Array. Seems like reasonable to me if that's the cause.

@jonleighton thoughts on this one?


jonleighton commented May 11, 2012

The #& alias for ``#mergewas removed at the request of @ernie. I can't remember the details but please use#merge` for this functionality. `#&` will just hit method_missing.

Ah yeah, I completely forgot & had been removed.. Thanks!


iamvery commented May 11, 2012

Thanks @jonleighton and @carlosantoniodasilva for your fast and brilliant replies. From your replies I found the rails core mailing list discussion at https://groups.google.com/forum/#!topic/rubyonrails-core/YxdcYEOGi3E that clears it all up. I also see where my misunderstanding of & came from. I guess this is just difficult to search for if you don't know the key word "merge".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment