aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/nodes/table_alias.rb
blob: 4f1d70ee54ee52e51d9b8abe513cccea3d61c19f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
module Arel
  module Nodes
    class TableAlias
      attr_reader :name, :relation, :columns

      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_s
        columns.find { |column| column.name == name }
      end
    end
  end
end