Permalink
Browse files

move alias building to the table node

  • Loading branch information...
1 parent a3a6313 commit a53c2beac42e0fea5dab9a334a066911beeba976 @tenderlove tenderlove committed Oct 15, 2013
@@ -91,21 +91,25 @@ def columns
@tables.flat_map { |t| t.columns }
end
- class Table < Struct.new(:table, :columns)
+ class Table < Struct.new(:name, :alias, :columns)
+ def table
+ Arel::Nodes::TableAlias.new name, self.alias
+ end
+
def columns
- super.map { |column| table[column.name].as Arel.sql column.alias }
+ t = table
+ super.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|
- table = join_part.aliased_table
columns = join_part.column_names.each_with_index.map { |column_name,j|
Aliases::Column.new column_name, "t#{i}_r#{j}"
}
- Aliases::Table.new(table, columns)
+ Aliases::Table.new(join_part.table, join_part.aliased_table_name, columns)
}
end
@@ -36,10 +36,6 @@ def each(&block)
children.each { |child| child.each(&block) }
end
- def aliased_table
- Arel::Nodes::TableAlias.new table, aliased_table_name
- end
-
# An Arel::Table for the active_record
def table
raise NotImplementedError

0 comments on commit a53c2be

Please sign in to comment.