aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation/where_clause.rb
diff options
context:
space:
mode:
authorSean Griffin <sean@thoughtbot.com>2015-01-27 09:41:25 -0700
committerSean Griffin <sean@thoughtbot.com>2015-01-27 09:41:25 -0700
commita5fcdae0a04d97dbd8fd05af6f352d3e09b2815f (patch)
treed4ecbd88d02dfe3215ebd06cfec24775652b5c63 /activerecord/lib/active_record/relation/where_clause.rb
parent16ce2eecd3eb23034555bb37b29c12985243d908 (diff)
downloadrails-a5fcdae0a04d97dbd8fd05af6f352d3e09b2815f.tar.gz
rails-a5fcdae0a04d97dbd8fd05af6f352d3e09b2815f.tar.bz2
rails-a5fcdae0a04d97dbd8fd05af6f352d3e09b2815f.zip
Move where grouping into `WhereClause`
Diffstat (limited to 'activerecord/lib/active_record/relation/where_clause.rb')
-rw-r--r--activerecord/lib/active_record/relation/where_clause.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/relation/where_clause.rb b/activerecord/lib/active_record/relation/where_clause.rb
index 8b9ba3e633..6c62332609 100644
--- a/activerecord/lib/active_record/relation/where_clause.rb
+++ b/activerecord/lib/active_record/relation/where_clause.rb
@@ -53,6 +53,10 @@ module ActiveRecord
}.to_h
end
+ def ast
+ Arel::Nodes::And.new(predicates_with_wrapped_sql_literals)
+ end
+
def ==(other)
other.is_a?(WhereClause) &&
predicates == other.predicates &&
@@ -128,6 +132,27 @@ module ActiveRecord
columns.include?(column.name)
end
end
+
+ def predicates_with_wrapped_sql_literals
+ non_empty_predicates.map do |node|
+ if Arel::Nodes::Equality === node
+ node
+ else
+ wrap_sql_literal(node)
+ end
+ end
+ end
+
+ def non_empty_predicates
+ predicates - ['']
+ end
+
+ def wrap_sql_literal(node)
+ if ::String === node
+ node = Arel.sql(node)
+ end
+ Arel::Nodes::Grouping.new(node)
+ end
end
end
end