diff options
author | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-05-15 18:42:16 -0700 |
---|---|---|
committer | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-05-15 18:42:16 -0700 |
commit | 4b300befaffd0486eb4ffbc63d64f04c85cd0219 (patch) | |
tree | c39859fdf23a4ecba4a13662aa7c9e3457bf93ac /lib/arel/relations | |
parent | 9376459a7186b794b29e11c55186135004e8f3b8 (diff) | |
download | rails-4b300befaffd0486eb4ffbc63d64f04c85cd0219.tar.gz rails-4b300befaffd0486eb4ffbc63d64f04c85cd0219.tar.bz2 rails-4b300befaffd0486eb4ffbc63d64f04c85cd0219.zip |
experimenting with new binding stuff
Diffstat (limited to 'lib/arel/relations')
-rw-r--r-- | lib/arel/relations/aggregation.rb | 38 | ||||
-rw-r--r-- | lib/arel/relations/compound.rb | 2 | ||||
-rw-r--r-- | lib/arel/relations/join.rb | 12 | ||||
-rw-r--r-- | lib/arel/relations/projection.rb | 4 | ||||
-rw-r--r-- | lib/arel/relations/recursion.rb | 4 |
5 files changed, 33 insertions, 27 deletions
diff --git a/lib/arel/relations/aggregation.rb b/lib/arel/relations/aggregation.rb index 955a71c0b0..55f24997cc 100644 --- a/lib/arel/relations/aggregation.rb +++ b/lib/arel/relations/aggregation.rb @@ -1,21 +1,25 @@ -Aggregation = Struct.new(:relation) do - def selects - [] - end - - def table - relation - end +module Arel + class Aggregation < Compound + include Recursion::BaseCase + + def initialize(relation) + @relation = relation + end + + def selects + [] + end - def relation_for(attribute) - relation - end - - def table_sql(formatter = Sql::TableReference.new(relation)) - relation.to_sql(formatter) - end + def table_sql(formatter = Sql::TableReference.new(relation)) + relation.to_sql(formatter) + end - def attributes - @attributes ||= relation.attributes.collect(&:to_attribute) + def attributes + @attributes ||= relation.attributes.collect(&:to_attribute) + end + + def ==(other) + self.class == other.class and self.relation == other.relation + end end end
\ No newline at end of file diff --git a/lib/arel/relations/compound.rb b/lib/arel/relations/compound.rb index 649d11e8b1..ca192a6e8a 100644 --- a/lib/arel/relations/compound.rb +++ b/lib/arel/relations/compound.rb @@ -4,7 +4,7 @@ module Arel hash_on :relation delegate :joins, :selects, :orders, :groupings, :inserts, :taken, :skipped, :name, :aggregation?, :column_for, - :engine, :table, :relation_for, :table_sql, + :engine, :table, :table_sql, :to => :relation def attributes diff --git a/lib/arel/relations/join.rb b/lib/arel/relations/join.rb index 14903cf01d..d42af5a499 100644 --- a/lib/arel/relations/join.rb +++ b/lib/arel/relations/join.rb @@ -35,12 +35,8 @@ module Arel (externalize(relation1).selects).collect { |s| s.bind(self) } end - def table - externalize(relation1).table - end - def table_sql(formatter = Sql::TableReference.new(self)) - externalize(table).table_sql(formatter) + externalize(relation1).table_sql(formatter) end def relation_for(attribute) @@ -59,4 +55,10 @@ module Arel relation.aggregation?? Aggregation.new(relation) : relation end end + + class Relation + def relation_for(attribute) + self[attribute] && self + end + end end
\ No newline at end of file diff --git a/lib/arel/relations/projection.rb b/lib/arel/relations/projection.rb index 8a08cda70c..66aa61f1d9 100644 --- a/lib/arel/relations/projection.rb +++ b/lib/arel/relations/projection.rb @@ -19,5 +19,9 @@ module Arel def aggregation? attributes.any?(&:aggregation?) end + + def relation_for(attribute) + self[attribute] && self || relation.relation_for(attribute) + end end end
\ No newline at end of file diff --git a/lib/arel/relations/recursion.rb b/lib/arel/relations/recursion.rb index 2c6024dc30..848b059507 100644 --- a/lib/arel/relations/recursion.rb +++ b/lib/arel/relations/recursion.rb @@ -5,10 +5,6 @@ module Arel self end - def relation_for(attribute) - self[attribute] and self - end - def table_sql(formatter = Sql::TableReference.new(self)) formatter.table self end |