diff options
author | deeeki <deeeki@gmail.com> | 2014-12-02 20:24:16 +0900 |
---|---|---|
committer | deeeki <deeeki@gmail.com> | 2014-12-03 00:20:01 +0900 |
commit | 66b84c9f442b6d25040a306416c4a863a2dfb397 (patch) | |
tree | 5cfd55cfef2eecfd87b78ce9aa8a78404346de53 /activerecord | |
parent | bc8cc56a2ae0b73276782d66b7dceba1ecd294a2 (diff) | |
download | rails-66b84c9f442b6d25040a306416c4a863a2dfb397.tar.gz rails-66b84c9f442b6d25040a306416c4a863a2dfb397.tar.bz2 rails-66b84c9f442b6d25040a306416c4a863a2dfb397.zip |
Allow to unscope where conditions using `arel_table` with Symbol
This commit fixes the following case.
User.where(User.arel_table[:created_at].lteq(1.year.ago)).unscope(where :created_at)
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/relation/query_methods.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/scoping/default_scoping_test.rb | 8 |
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 |