From 45646ec54c4c4a3c7340b79deea9e3cf76554f0b Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Fri, 24 Apr 2009 21:48:00 -0300 Subject: Added aggregation and to_attribute methods to Value --- lib/arel/primitives/value.rb | 8 ++++++++ lib/arel/relations/operations/join.rb | 16 ++++++++-------- lib/arel/relations/utilities/externalization.rb | 12 ++++++------ 3 files changed, 22 insertions(+), 14 deletions(-) (limited to 'lib/arel') diff --git a/lib/arel/primitives/value.rb b/lib/arel/primitives/value.rb index 74baa06e5b..36a7fb7c71 100644 --- a/lib/arel/primitives/value.rb +++ b/lib/arel/primitives/value.rb @@ -16,5 +16,13 @@ module Arel def bind(relation) Value.new(value, relation) end + + def aggregation? + false + end + + def to_attribute + value + end end end diff --git a/lib/arel/relations/operations/join.rb b/lib/arel/relations/operations/join.rb index a72030abf9..8fe89358d8 100644 --- a/lib/arel/relations/operations/join.rb +++ b/lib/arel/relations/operations/join.rb @@ -8,11 +8,11 @@ module Arel def initialize(join_sql, relation1, relation2 = Nil.instance, *predicates) @join_sql, @relation1, @relation2, @predicates = join_sql, relation1, relation2, predicates end - + def table_sql(formatter = Sql::TableReference.new(self)) relation1.externalize.table_sql(formatter) end - + def joins(environment, formatter = Sql::TableReference.new(environment)) @joins ||= begin this_join = [ @@ -29,29 +29,29 @@ module Arel @attributes ||= (relation1.externalize.attributes + relation2.externalize.attributes).collect { |a| a.bind(self) } end - + def wheres # TESTME bind to self? relation1.externalize.wheres end - + def ons @ons ||= @predicates.collect { |p| p.bind(self) } end - + # TESTME def externalizable? relation1.externalizable? or relation2.externalizable? end - + def join? true end end - + class Relation def join? false end end -end \ No newline at end of file +end diff --git a/lib/arel/relations/utilities/externalization.rb b/lib/arel/relations/utilities/externalization.rb index 4e9139a78a..3b9b2296dc 100644 --- a/lib/arel/relations/utilities/externalization.rb +++ b/lib/arel/relations/utilities/externalization.rb @@ -7,28 +7,28 @@ module Arel def wheres [] end - + def table_sql(formatter = Sql::TableReference.new(relation)) formatter.select relation.select_sql, self end - + def attributes @attributes ||= relation.attributes.collect(&:to_attribute).collect { |a| a.bind(self) } end - + # REMOVEME def name relation.name + '_external' end end - + class Relation def externalize @externalized ||= externalizable?? Externalization.new(self) : self end - + def externalizable? false end end -end \ No newline at end of file +end -- cgit v1.2.3