diff options
author | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-01-12 23:36:28 -0800 |
---|---|---|
committer | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-01-12 23:36:28 -0800 |
commit | eecab85b331c6bb716978262b418ab02ff4a22e9 (patch) | |
tree | f0f5be2e5961a2b884bd4258be8010d3d6dfd6be /lib | |
parent | 7c7044085617a66abb3f9bd37dc7c072701f03c7 (diff) | |
download | rails-eecab85b331c6bb716978262b418ab02ff4a22e9.tar.gz rails-eecab85b331c6bb716978262b418ab02ff4a22e9.tar.bz2 rails-eecab85b331c6bb716978262b418ab02ff4a22e9.zip |
experimenting with new aliasing terminology and interface
Diffstat (limited to 'lib')
-rw-r--r-- | lib/active_relation/primitives/aggregation.rb | 2 | ||||
-rw-r--r-- | lib/active_relation/relations/alias.rb | 4 | ||||
-rw-r--r-- | lib/active_relation/relations/base.rb | 2 | ||||
-rw-r--r-- | lib/active_relation/relations/rename.rb | 12 |
4 files changed, 8 insertions, 12 deletions
diff --git a/lib/active_relation/primitives/aggregation.rb b/lib/active_relation/primitives/aggregation.rb index a3c7747165..403c03fab5 100644 --- a/lib/active_relation/primitives/aggregation.rb +++ b/lib/active_relation/primitives/aggregation.rb @@ -10,7 +10,7 @@ module ActiveRelation end def to_sql(options = {}) - "#{function_sql}(#{@attribute.to_sql})" + "#{function_sql}(#{attribute.to_sql})" end def ==(other) diff --git a/lib/active_relation/relations/alias.rb b/lib/active_relation/relations/alias.rb index 97950ea5b3..5f4a10a672 100644 --- a/lib/active_relation/relations/alias.rb +++ b/lib/active_relation/relations/alias.rb @@ -10,10 +10,6 @@ module ActiveRelation def ==(other) relation == other.relation and self.alias == other.alias end - - def to_sql(options = {}) - super + " AS #{@alias}" - end end end end
\ No newline at end of file diff --git a/lib/active_relation/relations/base.rb b/lib/active_relation/relations/base.rb index b4654f8f4b..ea3404e7af 100644 --- a/lib/active_relation/relations/base.rb +++ b/lib/active_relation/relations/base.rb @@ -88,7 +88,7 @@ module ActiveRelation ("LIMIT #{limit.to_sql}" unless limit.blank?), ("OFFSET #{offset.to_sql}" unless offset.blank?) ].compact.join("\n") - options[:use_parens] ? "(#{sql})" : sql + (options[:use_parens] ? "(#{sql})" : sql) + (self.alias ? " AS #{self.alias}" : "") end alias_method :to_s, :to_sql diff --git a/lib/active_relation/relations/rename.rb b/lib/active_relation/relations/rename.rb index cff042dbc6..563b28922c 100644 --- a/lib/active_relation/relations/rename.rb +++ b/lib/active_relation/relations/rename.rb @@ -1,15 +1,15 @@ module ActiveRelation module Relations class Rename < Compound - attr_reader :schmattribute, :alias + attr_reader :schmattribute, :rename def initialize(relation, renames) - @schmattribute, @alias = renames.shift + @schmattribute, @rename = renames.shift @relation = renames.empty?? relation : Rename.new(relation, renames) end def ==(other) - relation == other.relation and schmattribute == other.schmattribute and self.alias == other.alias + relation == other.relation and schmattribute == other.schmattribute and self.rename == other.rename end def attributes @@ -17,13 +17,13 @@ module ActiveRelation end def qualify - Rename.new(relation.qualify, schmattribute.qualify => self.alias) + Rename.new(relation.qualify, schmattribute.qualify => self.rename) end protected def attribute(name) case - when name == self.alias then schmattribute.as(self.alias) + when name == self.rename then schmattribute.as(self.rename) when relation[name] == schmattribute then nil else relation[name] end @@ -31,7 +31,7 @@ module ActiveRelation private def substitute(a) - a == schmattribute ? a.as(self.alias) : a + a == schmattribute ? a.as(self.rename) : a end end end |