diff options
author | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-01-13 18:31:35 -0800 |
---|---|---|
committer | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-01-13 18:31:35 -0800 |
commit | bc4f6b8a29fc96c05efe0304ce7fad075818d2a2 (patch) | |
tree | 75f1b67bddf5ce5e247f57c5f9d8f8bde05c1f51 /lib/active_relation/primitives | |
parent | 2e63ac91302e2df397a286fdaf9cea51635071a6 (diff) | |
download | rails-bc4f6b8a29fc96c05efe0304ce7fad075818d2a2.tar.gz rails-bc4f6b8a29fc96c05efe0304ce7fad075818d2a2.tar.bz2 rails-bc4f6b8a29fc96c05efe0304ce7fad075818d2a2.zip |
experimenting with strategy pattern rather than conditional; not as terse, nor transparent, but i still feel it's better
Diffstat (limited to 'lib/active_relation/primitives')
-rw-r--r-- | lib/active_relation/primitives/aggregation.rb | 6 | ||||
-rw-r--r-- | lib/active_relation/primitives/attribute.rb | 6 |
2 files changed, 4 insertions, 8 deletions
diff --git a/lib/active_relation/primitives/aggregation.rb b/lib/active_relation/primitives/aggregation.rb index 403c03fab5..189eb33ac9 100644 --- a/lib/active_relation/primitives/aggregation.rb +++ b/lib/active_relation/primitives/aggregation.rb @@ -1,15 +1,13 @@ module ActiveRelation module Primitives - class Aggregation - include SqlBuilder - + class Aggregation attr_reader :attribute, :function_sql def initialize(attribute, function_sql) @attribute, @function_sql = attribute, function_sql end - def to_sql(options = {}) + 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 5ce3dfd531..6ebaf1b292 100644 --- a/lib/active_relation/primitives/attribute.rb +++ b/lib/active_relation/primitives/attribute.rb @@ -1,8 +1,6 @@ module ActiveRelation module Primitives class Attribute - include SqlBuilder - attr_reader :relation, :name, :alias def initialize(relation, name, aliaz = nil) @@ -77,8 +75,8 @@ module ActiveRelation end include Aggregations - def to_sql(options = {}) - "#{quote_table_name(relation.name)}.#{quote_column_name(name)}" + (options[:use_alias] && self.alias ? " AS #{self.alias.to_s.to_sql}" : "") + def to_sql(strategy = Sql::Predicate.new) + strategy.attribute relation.name, name, self.alias end end end |