aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/algebra/relations/operations/project.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/arel/algebra/relations/operations/project.rb')
-rw-r--r--lib/arel/algebra/relations/operations/project.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/arel/algebra/relations/operations/project.rb b/lib/arel/algebra/relations/operations/project.rb
new file mode 100644
index 0000000000..223d320e22
--- /dev/null
+++ b/lib/arel/algebra/relations/operations/project.rb
@@ -0,0 +1,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 ||= projections.collect { |p| p.bind(self) }
+ end
+
+ def externalizable?
+ attributes.any?(&:aggregation?) or relation.externalizable?
+ end
+ end
+end