diff options
author | Carl Lerche <carllerche@mac.com> | 2010-04-02 19:04:23 -0700 |
---|---|---|
committer | Carl Lerche <carllerche@mac.com> | 2010-04-02 19:04:23 -0700 |
commit | a46922e4a1089c9880c30b389e1e1d9dfbab02ae (patch) | |
tree | 2115e291ff1799d662bbb445b96060f2d029cc0d /lib/arel/engines/sql | |
parent | 233ee77f4511255ff2ff7c0b0ebf1cee13e7fc10 (diff) | |
download | rails-a46922e4a1089c9880c30b389e1e1d9dfbab02ae.tar.gz rails-a46922e4a1089c9880c30b389e1e1d9dfbab02ae.tar.bz2 rails-a46922e4a1089c9880c30b389e1e1d9dfbab02ae.zip |
Create an Arel::Header class representing a relation's attributes
Diffstat (limited to 'lib/arel/engines/sql')
-rw-r--r-- | lib/arel/engines/sql/relations/operations/join.rb | 2 | ||||
-rw-r--r-- | lib/arel/engines/sql/relations/table.rb | 12 |
2 files changed, 9 insertions, 5 deletions
diff --git a/lib/arel/engines/sql/relations/operations/join.rb b/lib/arel/engines/sql/relations/operations/join.rb index 7fad6400ad..9733657365 100644 --- a/lib/arel/engines/sql/relations/operations/join.rb +++ b/lib/arel/engines/sql/relations/operations/join.rb @@ -10,7 +10,7 @@ module Arel join_sql, relation2.externalize.table_sql(formatter), ("ON" unless predicates.blank?), - (ons + relation2.externalize.wheres).collect { |p| p.bind(environment).to_sql(Sql::WhereClause.new(environment)) }.join(' AND ') + (ons + relation2.externalize.wheres).collect { |p| p.bind(environment.relation).to_sql(Sql::WhereClause.new(environment)) }.join(' AND ') ].compact.join(" ") [relation1.joins(environment), this_join, relation2.joins(environment)].compact.join(" ") end diff --git a/lib/arel/engines/sql/relations/table.rb b/lib/arel/engines/sql/relations/table.rb index 8ee7a94357..7940fd781f 100644 --- a/lib/arel/engines/sql/relations/table.rb +++ b/lib/arel/engines/sql/relations/table.rb @@ -42,11 +42,14 @@ module Arel def attributes return @attributes if defined?(@attributes) if table_exists? - @attributes = columns.collect do |column| - Sql::Attributes.for(column).new(column, self, column.name.to_sym) + @attributes ||= begin + attrs = columns.collect do |column| + Sql::Attributes.for(column).new(column, self, column.name.to_sym) + end + Header.new(attrs) end else - [] + Header.new end end @@ -67,7 +70,8 @@ module Arel end def reset - @attributes = @columns = nil + @columns = nil + @attributes = Header.new([]) end def ==(other) |