diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-10-21 15:12:17 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-10-21 15:41:25 -0700 |
commit | 01da3593939ba6037a00f8eb9a2051b4b6f6f325 (patch) | |
tree | c712f35bba8cd44d4b18db0a798fdbcd7f1e1886 /activerecord | |
parent | db994076946f44d9b0fea23ca8715a74cb1f2b87 (diff) | |
download | rails-01da3593939ba6037a00f8eb9a2051b4b6f6f325.tar.gz rails-01da3593939ba6037a00f8eb9a2051b4b6f6f325.tar.bz2 rails-01da3593939ba6037a00f8eb9a2051b4b6f6f325.zip |
move helper class to the top
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/associations/join_dependency.rb | 84 |
1 files changed, 42 insertions, 42 deletions
diff --git a/activerecord/lib/active_record/associations/join_dependency.rb b/activerecord/lib/active_record/associations/join_dependency.rb index 4bcd69c69b..c3ac0680ea 100644 --- a/activerecord/lib/active_record/associations/join_dependency.rb +++ b/activerecord/lib/active_record/associations/join_dependency.rb @@ -4,6 +4,47 @@ module ActiveRecord autoload :JoinBase, 'active_record/associations/join_dependency/join_base' autoload :JoinAssociation, 'active_record/associations/join_dependency/join_association' + class Aliases # :nodoc: + def initialize(tables) + @tables = tables + @alias_cache = tables.each_with_object({}) { |table,h| + h[table.node] = table.columns.each_with_object({}) { |column,i| + i[column.name] = column.alias + } + } + @name_and_alias_cache = tables.each_with_object({}) { |table,h| + h[table.node] = table.columns.map { |column| + [column.name, column.alias] + } + } + end + + def columns + @tables.flat_map { |t| t.column_aliases } + end + + # An array of [column_name, alias] pairs for the table + def column_aliases(node) + @name_and_alias_cache[node] + end + + def column_alias(node, column) + @alias_cache[node][column] + end + + class Table < Struct.new(:node, :columns) + def table + Arel::Nodes::TableAlias.new node.table, node.aliased_table_name + end + + def column_aliases + t = table + columns.map { |column| t[column.name].as Arel.sql column.alias } + end + end + Column = Struct.new(:name, :alias) + end + attr_reader :alias_tracker, :base_klass, :join_root def self.make_tree(associations) @@ -73,53 +114,12 @@ module ActiveRecord walk join_root, oj.join_root else oj.join_root.children.flat_map { |child| - make_outer_joins(join_root, child) + make_outer_joins join_root, child } end } end - class Aliases - def initialize(tables) - @tables = tables - @alias_cache = tables.each_with_object({}) { |table,h| - h[table.node] = table.columns.each_with_object({}) { |column,i| - i[column.name] = column.alias - } - } - @name_and_alias_cache = tables.each_with_object({}) { |table,h| - h[table.node] = table.columns.map { |column| - [column.name, column.alias] - } - } - end - - def columns - @tables.flat_map { |t| t.column_aliases } - end - - # An array of [column_name, alias] pairs for the table - def column_aliases(node) - @name_and_alias_cache[node] - end - - def column_alias(node, column) - @alias_cache[node][column] - end - - class Table < Struct.new(:node, :columns) - def table - Arel::Nodes::TableAlias.new node.table, node.aliased_table_name - end - - def column_aliases - t = table - columns.map { |column| t[column.name].as Arel.sql column.alias } - end - end - Column = Struct.new(:name, :alias) - end - def aliases Aliases.new join_root.each_with_index.map { |join_part,i| columns = join_part.column_names.each_with_index.map { |column_name,j| |