Created
December 15, 2011 20:33
-
-
Save nashby/1482754 to your computer and use it in GitHub Desktop.
rails issue #3923
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/activerecord/lib/active_record/relation/spawn_methods.rb b/activerecord/lib/active_record/relation/spawn_methods.rb | |
index ba882be..b72aaa2 100644 | |
--- a/activerecord/lib/active_record/relation/spawn_methods.rb | |
+++ b/activerecord/lib/active_record/relation/spawn_methods.rb | |
@@ -34,7 +34,7 @@ module ActiveRecord | |
unless @where_values.empty? | |
# Remove duplicates, last one wins. | |
seen = Hash.new { |h,table| h[table] = {} } | |
- merged_wheres = merged_wheres.reverse.reject { |w| | |
+ merged_wheres = merged_wheres.uniq.reverse.reject { |w| | |
nuke = false | |
if w.respond_to?(:operator) && w.operator == :== | |
name = w.left.name | |
diff --git a/activerecord/test/cases/named_scope_test.rb b/activerecord/test/cases/named_scope_test.rb | |
index 4a09a87..c0c22be 100644 | |
--- a/activerecord/test/cases/named_scope_test.rb | |
+++ b/activerecord/test/cases/named_scope_test.rb | |
@@ -337,6 +337,11 @@ class NamedScopeTest < ActiveRecord::TestCase | |
end | |
end | |
+ def test_should_not_duplicates_where_values | |
+ where_values = Topic.where("1=1").foo.where_values | |
+ assert_equal ["1=1"], where_values | |
+ end | |
+ | |
def test_chaining_with_duplicate_joins | |
join = "INNER JOIN comments ON comments.post_id = posts.id" | |
post = Post.find(1) | |
diff --git a/activerecord/test/models/topic.rb b/activerecord/test/models/topic.rb | |
index fe424e6..a6657e2 100644 | |
--- a/activerecord/test/models/topic.rb | |
+++ b/activerecord/test/models/topic.rb | |
@@ -8,6 +8,8 @@ class Topic < ActiveRecord::Base | |
scope :approved, :conditions => {:approved => true} | |
scope :rejected, :conditions => {:approved => false} | |
+ scope :foo, proc { scoped } | |
+ | |
scope :by_lifo, :conditions => {:author_name => 'lifo'} | |
scope :approved_as_hash_condition, :conditions => {:topics => {:approved => true}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment