aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2014-12-02 14:38:05 -0200
committerRafael Mendonça França <rafaelmfranca@gmail.com>2014-12-02 14:38:05 -0200
commit4baa9c45f613dbee4f7b36383a1f1b4fc3e372af (patch)
tree52c7a0fb950df8c4491cd63949db8f0daa473c78
parentf09ecb0d45b02ce13375e15660fe7b4af8d59e87 (diff)
parent66b84c9f442b6d25040a306416c4a863a2dfb397 (diff)
downloadrails-4baa9c45f613dbee4f7b36383a1f1b4fc3e372af.tar.gz
rails-4baa9c45f613dbee4f7b36383a1f1b4fc3e372af.tar.bz2
rails-4baa9c45f613dbee4f7b36383a1f1b4fc3e372af.zip
Merge pull request #17881 from deeeki/unscope_arel_where
Allow to unscope where conditions by arel_table with symbol
-rw-r--r--activerecord/lib/active_record/relation/query_methods.rb2
-rw-r--r--activerecord/test/cases/scoping/default_scoping_test.rb8
2 files changed, 9 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb
index d58af01339..365851ada5 100644
--- a/activerecord/lib/active_record/relation/query_methods.rb
+++ b/activerecord/lib/active_record/relation/query_methods.rb
@@ -909,7 +909,7 @@ module ActiveRecord
case rel
when Arel::Nodes::Between, Arel::Nodes::In, Arel::Nodes::NotIn, Arel::Nodes::Equality, Arel::Nodes::NotEqual, Arel::Nodes::LessThanOrEqual, Arel::Nodes::GreaterThanOrEqual
subrelation = (rel.left.kind_of?(Arel::Attributes::Attribute) ? rel.left : rel.right)
- subrelation.name == target_value
+ subrelation.name.to_s == target_value
end
end
diff --git a/activerecord/test/cases/scoping/default_scoping_test.rb b/activerecord/test/cases/scoping/default_scoping_test.rb
index 5bdebe6ac7..0738df1b54 100644
--- a/activerecord/test/cases/scoping/default_scoping_test.rb
+++ b/activerecord/test/cases/scoping/default_scoping_test.rb
@@ -143,6 +143,14 @@ class DefaultScopingTest < ActiveRecord::TestCase
expected_5 = Developer.order('salary DESC').collect(&:name)
received_5 = DeveloperOrderedBySalary.where.not("name" => ["Jamis", "David"]).unscope(where: :name).collect(&:name)
assert_equal expected_5, received_5
+
+ expected_6 = Developer.order('salary DESC').collect(&:name)
+ received_6 = DeveloperOrderedBySalary.where(Developer.arel_table['name'].eq('David')).unscope(where: :name).collect(&:name)
+ assert_equal expected_6, received_6
+
+ expected_7 = Developer.order('salary DESC').collect(&:name)
+ received_7 = DeveloperOrderedBySalary.where(Developer.arel_table[:name].eq('David')).unscope(where: :name).collect(&:name)
+ assert_equal expected_7, received_7
end
def test_unscope_multiple_where_clauses