diff options
author | Matthew Draper <matthew@trebex.net> | 2014-10-27 04:20:13 +1030 |
---|---|---|
committer | Matthew Draper <matthew@trebex.net> | 2014-10-27 04:20:13 +1030 |
commit | 92449280107fe7134ffd7825a0c7e540a65adc24 (patch) | |
tree | 4610a7fbd634e174a8f3824fc5cbcbd94b6b2ff5 /activerecord | |
parent | 5a88d1e233e49c62c7bcbabad0d8489d0f7239ba (diff) | |
parent | 032605f08bdb8a911554276122b9feddff3eb1da (diff) | |
download | rails-92449280107fe7134ffd7825a0c7e540a65adc24.tar.gz rails-92449280107fe7134ffd7825a0c7e540a65adc24.tar.bz2 rails-92449280107fe7134ffd7825a0c7e540a65adc24.zip |
Merge pull request #17330 from DanOlson/rewhere
Fix Relation#rewhere to work with Range values
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/CHANGELOG.md | 4 | ||||
-rw-r--r-- | activerecord/lib/active_record/relation/query_methods.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/relation/where_chain_test.rb | 7 |
3 files changed, 12 insertions, 1 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index e0e107e89d..fa9e023d52 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,3 +1,7 @@ +* Fix `Relation.rewhere` to work with Range values. + + *Dan Olson* + * `AR::UnknownAttributeError` now includes the class name of a record. User.new(name: "Yuki Nishijima", project_attributes: {name: "kaminari"}) diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index bbddd28ccc..a53e8c9d0a 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -913,7 +913,7 @@ module ActiveRecord where_values.reject! do |rel| case rel - when Arel::Nodes::In, Arel::Nodes::NotIn, Arel::Nodes::Equality, Arel::Nodes::NotEqual + when Arel::Nodes::Between, Arel::Nodes::In, Arel::Nodes::NotIn, Arel::Nodes::Equality, Arel::Nodes::NotEqual subrelation = (rel.left.kind_of?(Arel::Attributes::Attribute) ? rel.left : rel.right) subrelation.name == target_value end diff --git a/activerecord/test/cases/relation/where_chain_test.rb b/activerecord/test/cases/relation/where_chain_test.rb index b9e69bdb08..478ac1bc42 100644 --- a/activerecord/test/cases/relation/where_chain_test.rb +++ b/activerecord/test/cases/relation/where_chain_test.rb @@ -149,5 +149,12 @@ module ActiveRecord assert_bound_ast value, Post.arel_table['title'], Arel::Nodes::Equality assert_equal 'alone', bind.last end + + def test_rewhere_with_range + relation = Post.where(comments_count: 1..3).rewhere(comments_count: 3..5) + + assert_equal 1, relation.where_values.size + assert_equal Post.where(comments_count: 3..5), relation + end end end |