aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation/query_methods.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-12-08 10:54:24 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2010-12-08 10:54:24 -0800
commit3499f882cc62e891057f806cf9a09a84f97a5e5c (patch)
tree7bb602a6061447ae7baa501f1dfcc3f353ae4070 /activerecord/lib/active_record/relation/query_methods.rb
parentddd6dee04343d3731b2f2fc558501c3707cde8fb (diff)
downloadrails-3499f882cc62e891057f806cf9a09a84f97a5e5c.tar.gz
rails-3499f882cc62e891057f806cf9a09a84f97a5e5c.tar.bz2
rails-3499f882cc62e891057f806cf9a09a84f97a5e5c.zip
renaming variables, making the join_ast method private
Diffstat (limited to 'activerecord/lib/active_record/relation/query_methods.rb')
-rw-r--r--activerecord/lib/active_record/relation/query_methods.rb78
1 files changed, 27 insertions, 51 deletions
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb
index 3a2cbc8dda..f9e5d7d925 100644
--- a/activerecord/lib/active_record/relation/query_methods.rb
+++ b/activerecord/lib/active_record/relation/query_methods.rb
@@ -162,29 +162,32 @@ module ActiveRecord
@arel ||= build_arel
end
- def custom_join_sql(joins)
- joins = joins.reject { |join| join.blank? }
+ def build_arel
+ arel = table
- return if joins.empty?
+ arel = build_joins(arel, @joins_values) unless @joins_values.empty?
- @implicit_readonly = true
+ arel = collapse_wheres(arel, (@where_values - ['']).uniq)
- arel = table.select_manager
+ arel = arel.having(*@having_values.uniq.reject{|h| h.blank?}) unless @having_values.empty?
- joins.each do |join|
- case join
- when Array
- join = Arel.sql(join.join(' ')) if array_of_strings?(join)
- when String
- join = Arel.sql(join)
- end
+ arel = arel.take(@limit_value) if @limit_value
+ arel = arel.skip(@offset_value) if @offset_value
- arel.join(join)
- end
+ arel = arel.group(*@group_values.uniq.reject{|g| g.blank?}) unless @group_values.empty?
- arel.join_sql
+ arel = arel.order(*@order_values.uniq.reject{|o| o.blank?}) unless @order_values.empty?
+
+ arel = build_select(arel, @select_values.uniq)
+
+ arel = arel.from(@from_value) if @from_value
+ arel = arel.lock(@lock_value) if @lock_value
+
+ arel
end
+ private
+
def custom_join_ast(table, joins)
joins = joins.reject { |join| join.blank? }
@@ -211,32 +214,6 @@ module ActiveRecord
head
end
- def build_arel
- arel = table
-
- arel = build_joins(arel, @joins_values) unless @joins_values.empty?
-
- arel = collapse_wheres(arel, (@where_values - ['']).uniq)
-
- arel = arel.having(*@having_values.uniq.reject{|h| h.blank?}) unless @having_values.empty?
-
- arel = arel.take(@limit_value) if @limit_value
- arel = arel.skip(@offset_value) if @offset_value
-
- arel = arel.group(*@group_values.uniq.reject{|g| g.blank?}) unless @group_values.empty?
-
- arel = arel.order(*@order_values.uniq.reject{|o| o.blank?}) unless @order_values.empty?
-
- arel = build_select(arel, @select_values.uniq)
-
- arel = arel.from(@from_value) if @from_value
- arel = arel.lock(@lock_value) if @lock_value
-
- arel
- end
-
- private
-
def collapse_wheres(arel, wheres)
equalities = wheres.grep(Arel::Nodes::Equality)
@@ -280,10 +257,9 @@ module ActiveRecord
stashed_association_joins = joins.grep(ActiveRecord::Associations::ClassMethods::JoinDependency::JoinAssociation)
non_association_joins = (joins - association_joins - stashed_association_joins)
- custom_joins = custom_join_sql(non_association_joins)
- ast = custom_join_ast(relation, non_association_joins)
+ join_ast = custom_join_ast(relation, non_association_joins)
- join_dependency = ActiveRecord::Associations::ClassMethods::JoinDependency.new(@klass, association_joins, ast)
+ join_dependency = ActiveRecord::Associations::ClassMethods::JoinDependency.new(@klass, association_joins, join_ast)
join_dependency.graft(*stashed_association_joins)
@@ -294,15 +270,15 @@ module ActiveRecord
end
if Arel::Table === relation
- relation.from(ast || relation)
+ relation.from(join_ast || relation)
else
- if relation.froms.length > 0 && ast
- ast.left = relation.froms.first
- relation.from ast
- elsif relation.froms.length == 0 && ast
- relation.from(ast)
+ if relation.froms.length > 0 && join_ast
+ join_ast.left = relation.froms.first
+ relation.from join_ast
+ elsif relation.froms.length == 0 && join_ast
+ relation.from(join_ast)
else
- relation.join(custom_joins)
+ relation
end
end
end