From cae95fc02af1fff885dca4a29b2fd3711b809cab Mon Sep 17 00:00:00 2001 From: Nick Kallen Date: Sun, 16 Mar 2008 17:49:06 -0700 Subject: projections now support string passthrough - there is a weird inconsistency in where bind is called on values; this needs to be resolved --- lib/active_relation/relations/relation.rb | 4 ++-- lib/active_relation/sql.rb | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/active_relation/relations/relation.rb b/lib/active_relation/relations/relation.rb index fa66bd039b..88d1bce4a8 100644 --- a/lib/active_relation/relations/relation.rb +++ b/lib/active_relation/relations/relation.rb @@ -42,7 +42,7 @@ module ActiveRelation end def project(*attributes) - Projection.new(self, *attributes.collect {|a| a.bind(self)}) + Projection.new(self, *attributes) end def as(aliaz) @@ -103,7 +103,7 @@ module ActiveRelation def to_sql(formatter = Sql::SelectStatement.new(engine)) formatter.select [ - "SELECT #{attributes.collect { |a| a.to_sql(Sql::SelectExpression.new(engine)) }.join(', ')}", + "SELECT #{attributes.collect { |a| a.to_sql(Sql::SelectClause.new(engine)) }.join(', ')}", "FROM #{table_sql}", (joins unless joins.blank? ), ("WHERE #{selects.collect { |s| s.to_sql(Sql::WhereClause.new(engine)) }.join("\n\tAND ")}" unless selects.blank? ), diff --git a/lib/active_relation/sql.rb b/lib/active_relation/sql.rb index 3a773fdf6e..0b9b0fc18b 100644 --- a/lib/active_relation/sql.rb +++ b/lib/active_relation/sql.rb @@ -14,7 +14,7 @@ module ActiveRelation end end - class SelectExpression < Formatter + class SelectClause < Formatter def attribute(relation_name, attribute_name, aliaz) "#{quote_table_name(relation_name)}.#{quote_column_name(attribute_name)}" + (aliaz ? " AS #{quote(aliaz.to_s)}" : "") end @@ -22,6 +22,10 @@ module ActiveRelation def select(select_sql, aliaz) "(#{select_sql})" + (aliaz ? " AS #{quote(aliaz)}" : "") end + + def value(value) + value + end end class PassThrough < Formatter -- cgit v1.2.3