diff options
Diffstat (limited to 'lib/arel/engines/sql/relations/relation.rb')
-rw-r--r-- | lib/arel/engines/sql/relations/relation.rb | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/arel/engines/sql/relations/relation.rb b/lib/arel/engines/sql/relations/relation.rb index deca9b19cb..448cf7951d 100644 --- a/lib/arel/engines/sql/relations/relation.rb +++ b/lib/arel/engines/sql/relations/relation.rb @@ -13,7 +13,7 @@ module Arel query = build_query \ "SELECT #{select_clauses.kind_of?(::Array) ? select_clauses.join("") : select_clauses.to_s}", - "FROM #{table_sql(Sql::TableReference.new(self))}", + "FROM #{from_clauses}", (joins(self) unless joins(self).blank? ), ("WHERE #{where_clauses.join("\n\tAND ")}" unless wheres.blank? ), ("GROUP BY #{group_clauses.join(', ')}" unless groupings.blank? ) @@ -27,7 +27,7 @@ module Arel else build_query \ "SELECT #{select_clauses.join(', ')}", - "FROM #{table_sql(Sql::TableReference.new(self))}", + "FROM #{from_clauses}", (joins(self) unless joins(self).blank? ), ("WHERE #{where_clauses.join("\n\tAND ")}" unless wheres.blank? ), ("GROUP BY #{group_clauses.join(', ')}" unless groupings.blank? ), @@ -51,6 +51,10 @@ module Arel parts.compact.join(" ") end + def from_clauses + sources.blank? ? table_sql(Sql::TableReference.new(self)) : sources + end + def select_clauses attributes.collect { |a| a.to_sql(Sql::SelectClause.new(self)) } end |