1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

make table aliases cheaper to allocate

This commit is contained in:
Aaron Patterson 2010-11-24 12:01:05 -08:00
parent 6667cfb995
commit f092ae544f
2 changed files with 4 additions and 8 deletions

View file

@ -1,20 +1,16 @@
module Arel
module Nodes
class TableAlias
attr_reader :name, :relation, :columns
attr_reader :name, :relation
alias :table_alias :name
def initialize name, relation
@name = name
@relation = relation
@columns = relation.columns.map { |column|
column.dup.tap { |col| col.relation = self }
}
end
def [] name
name = name.to_sym
columns.find { |column| column.name == name }
Attribute.new self, name
end
end
end

View file

@ -34,8 +34,8 @@ module Arel
end
end
def alias
Nodes::TableAlias.new("#{name}_2", self).tap do |node|
def alias name = "#{self.name}_2"
Nodes::TableAlias.new(name, self).tap do |node|
@aliases << node
end
end