aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/algebra/relations/operations/project.rb
blob: 49d0e1be36a9cab86acef4d8193d07eb8bd9b71d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
module Arel
  class Project < Compound
    attributes :relation, :projections
    deriving :==

    def initialize(relation, *projections, &block)
      @relation = relation
      @projections = (projections + arguments_from_block(relation, &block)) \
        .collect { |p| p.bind(relation) }
    end

    def attributes
      @attributes ||= Header.new(projections).bind(self)
    end

    def externalizable?
      attributes.any? { |a| a.respond_to?(:aggregation?) && a.aggregation? } || relation.externalizable?
    end
  end
end