Skip to content

Commit

Permalink
make table aliases cheaper to allocate
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Nov 24, 2010
1 parent 6667cfb commit f092ae5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
8 changes: 2 additions & 6 deletions lib/arel/nodes/table_alias.rb
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/arel/table.rb
Expand Up @@ -34,8 +34,8 @@ def primary_key
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
Expand Down

0 comments on commit f092ae5

Please sign in to comment.