Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Closed
iamvery opened this Issue · 4 comments

3 participants

@iamvery

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

Thanks!

@carlosantoniodasilva

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
Collaborator

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

@carlosantoniodasilva

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

@iamvery

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
Something went wrong with that request. Please try again.