diff options
author | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-01-16 22:55:06 -0800 |
---|---|---|
committer | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-01-16 22:55:06 -0800 |
commit | b47ac80a17d7a74e1b5deac0e63a72960a4da453 (patch) | |
tree | de13e27979148c8a39c396298cc789348d4acb2e /lib/active_relation/primitives | |
parent | b5a2057fcd5dfcac3682a565f2ba15281f5dcbb2 (diff) | |
download | rails-b47ac80a17d7a74e1b5deac0e63a72960a4da453.tar.gz rails-b47ac80a17d7a74e1b5deac0e63a72960a4da453.tar.bz2 rails-b47ac80a17d7a74e1b5deac0e63a72960a4da453.zip |
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
Diffstat (limited to 'lib/active_relation/primitives')
-rw-r--r-- | lib/active_relation/primitives/aggregation.rb | 4 | ||||
-rw-r--r-- | lib/active_relation/primitives/attribute.rb | 21 |
2 files changed, 18 insertions, 7 deletions
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 |