aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation/query_methods.rb
diff options
context:
space:
mode:
authorSean Griffin <sean@thoughtbot.com>2015-01-27 10:40:13 -0700
committerSean Griffin <sean@thoughtbot.com>2015-01-27 10:56:31 -0700
commitae299dd45d1fff2775d631e240593d4d3684673e (patch)
tree0bb3f0ee0a30aa287b7429f7de381e3c2fb50a8c /activerecord/lib/active_record/relation/query_methods.rb
parentd26dd00854c783bcb1249168bb3f4adf9f99be6c (diff)
downloadrails-ae299dd45d1fff2775d631e240593d4d3684673e.tar.gz
rails-ae299dd45d1fff2775d631e240593d4d3684673e.tar.bz2
rails-ae299dd45d1fff2775d631e240593d4d3684673e.zip
Minor refactorings on `Relation#build_joins`
Attempting to grok this code by refactoring it as I go through it.
Diffstat (limited to 'activerecord/lib/active_record/relation/query_methods.rb')
-rw-r--r--activerecord/lib/active_record/relation/query_methods.rb39
1 files changed, 13 insertions, 26 deletions
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb
index 9bd55de347..a270f23d7d 100644
--- a/activerecord/lib/active_record/relation/query_methods.rb
+++ b/activerecord/lib/active_record/relation/query_methods.rb
@@ -2,7 +2,6 @@ require "active_record/relation/from_clause"
require "active_record/relation/where_clause"
require "active_record/relation/where_clause_factory"
require 'active_model/forbidden_attributes_protection'
-require 'active_support/core_ext/array/wrap'
require 'active_support/core_ext/string/filters'
module ActiveRecord
@@ -892,22 +891,6 @@ module ActiveRecord
self.send(unscope_code, result)
end
- def custom_join_ast(table, joins)
- joins = joins.reject(&:blank?)
-
- return [] if joins.empty?
-
- joins.map! do |join|
- case join
- when Array
- join = Arel.sql(join.join(' ')) if array_of_strings?(join)
- when String
- join = Arel.sql(join)
- end
- table.create_string_join(join)
- end
- end
-
def association_for_table(table_name)
table_name = table_name.to_s
@klass._reflect_on_association(table_name) ||
@@ -941,13 +924,14 @@ module ActiveRecord
raise 'unknown class: %s' % join.class.name
end
end
+ buckets.default = []
- association_joins = buckets[:association_join] || []
- stashed_association_joins = buckets[:stashed_join] || []
- join_nodes = (buckets[:join_node] || []).uniq
- string_joins = (buckets[:string_join] || []).map(&:strip).uniq
+ association_joins = buckets[:association_join]
+ stashed_association_joins = buckets[:stashed_join]
+ join_nodes = buckets[:join_node].uniq
+ string_joins = buckets[:string_join].map(&:strip).uniq
- join_list = join_nodes + custom_join_ast(manager, string_joins)
+ join_list = join_nodes + convert_join_strings_to_ast(manager, string_joins)
join_dependency = ActiveRecord::Associations::JoinDependency.new(
@klass,
@@ -967,6 +951,13 @@ module ActiveRecord
manager
end
+ def convert_join_strings_to_ast(table, joins)
+ joins
+ .flatten
+ .reject(&:blank?)
+ .map { |join| table.create_string_join(Arel.sql(join)) }
+ end
+
def build_select(arel, selects)
if !selects.empty?
expanded_select = selects.map do |field|
@@ -1001,10 +992,6 @@ module ActiveRecord
end
end
- def array_of_strings?(o)
- o.is_a?(Array) && o.all? { |obj| obj.is_a?(String) }
- end
-
def build_order(arel)
orders = order_values.uniq
orders.reject!(&:blank?)