Permalink
Browse files

Intersection between a relation and an array works in both directions.

Back port of commits a513f8f marklazz (author) & 1c28376  Kanetontli (author)
  • Loading branch information...
1 parent 3479c1e commit 14f1b09b46f3bd01634d299a680804e9aee8a96c @mikel mikel committed Sep 11, 2010
@@ -5,6 +5,7 @@ module SpawnMethods
def merge(r)
merged_relation = clone
return merged_relation unless r
+ return to_a & r if r.is_a?(Array)
Relation::ASSOCIATION_METHODS.each do |method|
value = r.send(:"#{method}_values")
@@ -699,5 +699,12 @@ def test_order_using_scoping
assert_equal 'zyke', car.name
end
+ def test_intersection_with_array
+ relation = Author.where(:name => "David")
+ rails_author = relation.first
+
+ assert_equal [rails_author], [rails_author] & relation
+ assert_equal [rails_author], relation & [rails_author]
+ end
end

0 comments on commit 14f1b09

Please sign in to comment.