diff options
author | Maxime Lapointe <hunter_spawn@hotmail.com> | 2017-07-13 11:08:35 -0400 |
---|---|---|
committer | Maxime Lapointe <hunter_spawn@hotmail.com> | 2017-07-13 13:18:08 -0400 |
commit | 425ba83c28214ca97c5d3600c16ad7a796cd33e6 (patch) | |
tree | 887d19657bb887dc8438ef52bb2702dfeb041cee /activerecord/lib/active_record/relation | |
parent | 472f39f781e5ebf5dcb19bb432572ba68dfcceca (diff) | |
download | rails-425ba83c28214ca97c5d3600c16ad7a796cd33e6.tar.gz rails-425ba83c28214ca97c5d3600c16ad7a796cd33e6.tar.bz2 rails-425ba83c28214ca97c5d3600c16ad7a796cd33e6.zip |
Bugfix: unscope(where: [columns]) would not remove the correct binds sometimes
Post.where(id: 1).or(Post.where(id: 2)).where(foo: 3).unscope(where: :foo).where_clause.binds.map(&:value)
Would return [2, 3] instead of the expected [1,2]
Diffstat (limited to 'activerecord/lib/active_record/relation')
-rw-r--r-- | activerecord/lib/active_record/relation/where_clause.rb | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/relation/where_clause.rb b/activerecord/lib/active_record/relation/where_clause.rb index 119910ee79..7542ea4d8c 100644 --- a/activerecord/lib/active_record/relation/where_clause.rb +++ b/activerecord/lib/active_record/relation/where_clause.rb @@ -136,10 +136,11 @@ module ActiveRecord binds_index = 0 predicates = self.predicates.reject do |node| + binds_contains = node.grep(Arel::Nodes::BindParam).size if node.is_a?(Arel::Nodes::Node) + except = \ case node when Arel::Nodes::Between, Arel::Nodes::In, Arel::Nodes::NotIn, Arel::Nodes::Equality, Arel::Nodes::NotEqual, Arel::Nodes::LessThan, Arel::Nodes::LessThanOrEqual, Arel::Nodes::GreaterThan, Arel::Nodes::GreaterThanOrEqual - binds_contains = node.grep(Arel::Nodes::BindParam).size subrelation = (node.left.kind_of?(Arel::Attributes::Attribute) ? node.left : node.right) columns.include?(subrelation.name.to_s) end |