Remove ActiveRecord::Relation#& alias for 'merge' ? (or at least only reference and not use in AR)

Would the core team be open to the removal of the '&' alias for
ActiveRecord::Relation#merge?

The reason is that in Ruby the '&' operator refers to an intersection
of two sets of data, not a merge. (within the context of the Array
class)

Recently Arel added support for SQL Set Operators:

2-0-stable: https://github.com/rails/arel/commit/9e816c406399139d9ca76d2089df7f2d94d4fb8b
master: https://github.com/rails/arel/commit/74caeaad157e79853b9c6804f561d3c70eea2346
and https://github.com/rails/arel/commit/d532b7ee430c5d0c412ab9f1a5e0dd3ebc47f86b

So this allows for a higher level abstraction to use the Array class'
convention:

'|' => Union
'+' => UnionALL
'&' => Intersect
'-' => Except (Minus for Oracle)

to operate on two ActiveRecord::Relation instances.

This is sitting as a pending pull request on MetaWhere:
https://github.com/ernie/meta_where/pull/12

Ernie Miller and I have been going back and forth. Ernie points out
that ActiveRecord is using the alias '&' a few times in the code base
instead of 'merge' and overriding this method in MetaWhere would cause
some major issues.

Thoughts?

Would the core team be open to the removal of the '&' alias for
ActiveRecord::Relation#merge?

Yes, this seems fine to me. We should add a deprecation warning in
3.0.x, then remove the method in master.

The reason is that in Ruby the '&' operator refers to an intersection
of two sets of data, not a merge. (within the context of the Array
class)

Recently Arel added support for SQL Set Operators:

2-0-stable: https://github.com/rails/arel/commit/9e816c406399139d9ca76d2089df7f2d94d4fb8b
master: https://github.com/rails/arel/commit/74caeaad157e79853b9c6804f561d3c70eea2346
and https://github.com/rails/arel/commit/d532b7ee430c5d0c412ab9f1a5e0dd3ebc47f86b

So this allows for a higher level abstraction to use the Array class'
convention:

'|' => Union
'+' => UnionALL
'&' => Intersect
'-' => Except (Minus for Oracle)

to operate on two ActiveRecord::Relation instances.

This is sitting as a pending pull request on MetaWhere:
https://github.com/ernie/meta_where/pull/12

Ernie Miller and I have been going back and forth. Ernie points out
that ActiveRecord is using the alias '&' a few times in the code base
instead of 'merge' and overriding this method in MetaWhere would cause
some major issues.

Thoughts?

At the very least, file a ticket for me so I don't forget. Patches
would be nice too, but aren't necessary. :wink:

Thanks, Aaron! I’ll get a patch for master ready shortly.

Patches for 3-0-stable and master are both at
https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/6407-deprecate-relation-in-3-0-stable-and-remove-in-master

Sweet! I totally missed out on the follow ups to this thread. Thanks!

- Brian