aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation/where_clause.rb
diff options
context:
space:
mode:
authorSean Griffin <sean@thoughtbot.com>2015-01-25 17:30:42 -0700
committerSean Griffin <sean@thoughtbot.com>2015-01-25 17:30:42 -0700
commitd6110799c2573080897410f9836f5aa623b197ea (patch)
treebfbfc983b3f8558d8dd85a042354c8eb59f333b9 /activerecord/lib/active_record/relation/where_clause.rb
parent7227e4fba17f4a50e53a5486a3b956a6c7c26697 (diff)
downloadrails-d6110799c2573080897410f9836f5aa623b197ea.tar.gz
rails-d6110799c2573080897410f9836f5aa623b197ea.tar.bz2
rails-d6110799c2573080897410f9836f5aa623b197ea.zip
Move `where_unscoping` logic over to `WhereClause`
Diffstat (limited to 'activerecord/lib/active_record/relation/where_clause.rb')
-rw-r--r--activerecord/lib/active_record/relation/where_clause.rb23
1 files changed, 23 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/relation/where_clause.rb b/activerecord/lib/active_record/relation/where_clause.rb
index f03f95df0b..ca9c7d19a7 100644
--- a/activerecord/lib/active_record/relation/where_clause.rb
+++ b/activerecord/lib/active_record/relation/where_clause.rb
@@ -24,6 +24,13 @@ module ActiveRecord
)
end
+ def except(*columns)
+ WhereClause.new(
+ predicates_except(columns),
+ binds_except(columns),
+ )
+ end
+
def ==(other)
other.is_a?(WhereClause) &&
predicates == other.predicates &&
@@ -83,6 +90,22 @@ module ActiveRecord
Arel::Nodes::Not.new(node)
end
end
+
+ def predicates_except(columns)
+ predicates.reject do |node|
+ case node
+ when Arel::Nodes::Between, Arel::Nodes::In, Arel::Nodes::NotIn, Arel::Nodes::Equality, Arel::Nodes::NotEqual, Arel::Nodes::LessThanOrEqual, Arel::Nodes::GreaterThanOrEqual
+ subrelation = (node.left.kind_of?(Arel::Attributes::Attribute) ? node.left : node.right)
+ columns.include?(subrelation.name.to_s)
+ end
+ end
+ end
+
+ def binds_except(columns)
+ binds.reject do |column, _|
+ columns.include?(column.name)
+ end
+ end
end
end
end