From 191b2b7b7e6e2cf4fc5a24321bc9b1e593f96551 Mon Sep 17 00:00:00 2001 From: Nick Kallen Date: Wed, 21 May 2008 00:23:32 -0700 Subject: externalization now includes limits --- lib/arel/primitives/attribute.rb | 2 +- lib/arel/relations/operations/group.rb | 2 +- lib/arel/relations/operations/join.rb | 1 + lib/arel/relations/operations/order.rb | 2 +- lib/arel/relations/operations/project.rb | 2 +- lib/arel/relations/operations/where.rb | 2 +- lib/arel/relations/relation.rb | 4 +++ lib/arel/relations/utilities.rb | 2 +- lib/arel/relations/utilities/aggregation.rb | 33 ------------------------ lib/arel/relations/utilities/externalization.rb | 34 +++++++++++++++++++++++++ 10 files changed, 45 insertions(+), 39 deletions(-) delete mode 100644 lib/arel/relations/utilities/aggregation.rb create mode 100644 lib/arel/relations/utilities/externalization.rb (limited to 'lib') diff --git a/lib/arel/primitives/attribute.rb b/lib/arel/primitives/attribute.rb index dffe24d121..30885dd129 100644 --- a/lib/arel/primitives/attribute.rb +++ b/lib/arel/primitives/attribute.rb @@ -75,7 +75,7 @@ module Arel end def find_correlate_in(relation) - relation[self] + relation[self] || self end def descends_from?(other) diff --git a/lib/arel/relations/operations/group.rb b/lib/arel/relations/operations/group.rb index 253c4215b6..04fd9fea62 100644 --- a/lib/arel/relations/operations/group.rb +++ b/lib/arel/relations/operations/group.rb @@ -5,7 +5,7 @@ module Arel def initialize(relation, *groupings, &block) @relation = relation - @groupings = (groupings + (block_given?? [yield(self)] : [])).collect { |g| g.bind(relation) } + @groupings = (groupings + (block_given?? [yield(relatoin)] : [])).collect { |g| g.bind(relation) } end def externalizable? diff --git a/lib/arel/relations/operations/join.rb b/lib/arel/relations/operations/join.rb index 8025db095e..a72030abf9 100644 --- a/lib/arel/relations/operations/join.rb +++ b/lib/arel/relations/operations/join.rb @@ -31,6 +31,7 @@ module Arel end def wheres + # TESTME bind to self? relation1.externalize.wheres end diff --git a/lib/arel/relations/operations/order.rb b/lib/arel/relations/operations/order.rb index 82924806e2..05af3fde4d 100644 --- a/lib/arel/relations/operations/order.rb +++ b/lib/arel/relations/operations/order.rb @@ -5,7 +5,7 @@ module Arel def initialize(relation, *orderings, &block) @relation = relation - @orderings = (orderings + (block_given?? [yield(self)] : [])).collect { |o| o.bind(relation) } + @orderings = (orderings + (block_given?? [yield(relation)] : [])).collect { |o| o.bind(relation) } end # TESTME diff --git a/lib/arel/relations/operations/project.rb b/lib/arel/relations/operations/project.rb index c92a9df5a5..d7835edda4 100644 --- a/lib/arel/relations/operations/project.rb +++ b/lib/arel/relations/operations/project.rb @@ -5,7 +5,7 @@ module Arel def initialize(relation, *projections, &block) @relation = relation - @projections = (projections + (block_given?? [yield(self)] : [])).collect { |p| p.bind(relation) } + @projections = (projections + (block_given?? [yield(relation)] : [])).collect { |p| p.bind(relation) } end def attributes diff --git a/lib/arel/relations/operations/where.rb b/lib/arel/relations/operations/where.rb index 9acb8ae3c6..8882f36104 100644 --- a/lib/arel/relations/operations/where.rb +++ b/lib/arel/relations/operations/where.rb @@ -4,7 +4,7 @@ module Arel deriving :== def initialize(relation, *predicates, &block) - predicate = block_given?? yield(self) : predicates.shift + predicate = block_given?? yield(relation) : predicates.shift @relation = predicates.empty?? relation : Where.new(relation, *predicates) @predicate = predicate.bind(@relation) end diff --git a/lib/arel/relations/relation.rb b/lib/arel/relations/relation.rb index 1e2ac9f2be..a2d8bba6ea 100644 --- a/lib/arel/relations/relation.rb +++ b/lib/arel/relations/relation.rb @@ -39,6 +39,10 @@ module Arel self end + def root + self + end + def christener @christener ||= Sql::Christener.new end diff --git a/lib/arel/relations/utilities.rb b/lib/arel/relations/utilities.rb index 02c2e0a952..454d455359 100644 --- a/lib/arel/relations/utilities.rb +++ b/lib/arel/relations/utilities.rb @@ -1,5 +1,5 @@ require 'arel/relations/utilities/compound' require 'arel/relations/utilities/recursion' require 'arel/relations/utilities/nil' -require 'arel/relations/utilities/aggregation' +require 'arel/relations/utilities/externalization' require 'arel/relations/utilities/recursion' \ No newline at end of file diff --git a/lib/arel/relations/utilities/aggregation.rb b/lib/arel/relations/utilities/aggregation.rb deleted file mode 100644 index bdc7650a20..0000000000 --- a/lib/arel/relations/utilities/aggregation.rb +++ /dev/null @@ -1,33 +0,0 @@ -module Arel - class Externalization < Compound - attributes :relation - deriving :initialize, :== - include Recursion::BaseCase - - 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 - - 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 diff --git a/lib/arel/relations/utilities/externalization.rb b/lib/arel/relations/utilities/externalization.rb new file mode 100644 index 0000000000..4e9139a78a --- /dev/null +++ b/lib/arel/relations/utilities/externalization.rb @@ -0,0 +1,34 @@ +module Arel + class Externalization < Compound + attributes :relation + deriving :initialize, :== + include Recursion::BaseCase + + 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 -- cgit v1.2.3