From b47ac80a17d7a74e1b5deac0e63a72960a4da453 Mon Sep 17 00:00:00 2001 From: Nick Kallen Date: Wed, 16 Jan 2008 22:55:06 -0800 Subject: adding grouping functionality; added some dummy code ("Schmoin") for experimenting with aggregate joins. need to resolve the ambiguity in the #as operator between (SELECT * FROM foo AS bar) vs. (SELECT * FROM foo) AS bar --- lib/active_relation/primitives/aggregation.rb | 4 ++++ lib/active_relation/primitives/attribute.rb | 21 ++++++++++++++------- 2 files changed, 18 insertions(+), 7 deletions(-) (limited to 'lib/active_relation/primitives') diff --git a/lib/active_relation/primitives/aggregation.rb b/lib/active_relation/primitives/aggregation.rb index 48f8946835..26348fb35e 100644 --- a/lib/active_relation/primitives/aggregation.rb +++ b/lib/active_relation/primitives/aggregation.rb @@ -6,6 +6,10 @@ module ActiveRelation @attribute, @function_sql = attribute, function_sql end + def substitute(new_relation) + Aggregation.new(attribute.substitute(new_relation), function_sql) + end + def to_sql(strategy = nil) "#{function_sql}(#{attribute.to_sql})" end diff --git a/lib/active_relation/primitives/attribute.rb b/lib/active_relation/primitives/attribute.rb index 90bbe8012b..eb167b1a66 100644 --- a/lib/active_relation/primitives/attribute.rb +++ b/lib/active_relation/primitives/attribute.rb @@ -6,18 +6,25 @@ module ActiveRelation @relation, @name, @alias = relation, name, aliaz end - def as(aliaz = nil) - Attribute.new(relation, name, aliaz) - end + module Transformations + def as(aliaz = nil) + Attribute.new(relation, name, aliaz) + end + + def substitute(new_relation) + Attribute.new(new_relation, name, @alias) + end + def qualify + self.as(qualified_name) + end + end + include Transformations + def qualified_name "#{relation.name}.#{name}" end - def qualify - self.as(qualified_name) - end - def ==(other) relation == other.relation and name == other.name and @alias == other.alias end -- cgit v1.2.3