From e468a62dc89d4d3c2a16a6d3e8fd78342a2732df Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 5 Jan 2011 09:47:13 -0800 Subject: use arel ast construction rather than generating strings --- .../associations/has_and_belongs_to_many_association.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb b/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb index f3b1c9de3f..a8e1ea21c4 100644 --- a/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb +++ b/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb @@ -68,7 +68,13 @@ module ActiveRecord end def construct_joins - "INNER JOIN #{@owner.connection.quote_table_name @reflection.options[:join_table]} ON #{@reflection.quoted_table_name}.#{@reflection.klass.primary_key} = #{@owner.connection.quote_table_name @reflection.options[:join_table]}.#{@reflection.association_foreign_key}" + right = join_table + left = @reflection.klass.arel_table + + condition = left[@reflection.klass.primary_key].eq( + right[@reflection.association_foreign_key]) + + right.create_join(right, right.create_on(condition)) end def join_table -- cgit v1.2.3