From d6840f914a32bff4d73f23c3f5c64c5397f8b400 Mon Sep 17 00:00:00 2001 From: Lauro Caetano Date: Thu, 3 Apr 2014 22:07:03 -0300 Subject: The comparison between `Relation` and `CollectionProxy` should be consistent. Example: author.posts == Post.where(author_id: author.id) # => true Post.where(author_id: author.id) == author.posts # => true Fixes #13506 --- activerecord/lib/active_record/relation.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index d1764a2bb2..4adc8a3862 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -569,6 +569,8 @@ module ActiveRecord # Compares two relations for equality. def ==(other) case other + when Associations::CollectionProxy + self == other.to_a when Relation other.to_sql == to_sql when Array -- cgit v1.2.3 From 24052f925f5f52f74646610a843eb3b98845ac77 Mon Sep 17 00:00:00 2001 From: Lauro Caetano Date: Fri, 11 Apr 2014 19:51:38 -0300 Subject: Make the comparison between 'Relation' and 'AssociationRelation' consistent. --- activerecord/lib/active_record/association_relation.rb | 4 ++++ activerecord/lib/active_record/relation.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/association_relation.rb b/activerecord/lib/active_record/association_relation.rb index ef9650d482..45f1b07f69 100644 --- a/activerecord/lib/active_record/association_relation.rb +++ b/activerecord/lib/active_record/association_relation.rb @@ -17,6 +17,10 @@ module ActiveRecord @association.empty? end + def ==(other) + other == to_a + end + private def exec_queries diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index 4adc8a3862..709edbee88 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -569,7 +569,7 @@ module ActiveRecord # Compares two relations for equality. def ==(other) case other - when Associations::CollectionProxy + when Associations::CollectionProxy, AssociationRelation self == other.to_a when Relation other.to_sql == to_sql -- cgit v1.2.3