diff options
author | Jon Leighton <j@jonathanleighton.com> | 2010-12-24 00:29:04 +0000 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2010-12-26 19:38:04 +0000 |
commit | e8ada11aac28f0850f0e485acacf34e7eb81aa19 (patch) | |
tree | 8d336ca01b37d42bdaa904d00f3b7daa11e24e84 /activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb | |
parent | f2230c06edf9c1ca72892bbe00e816be1dafa840 (diff) | |
download | rails-e8ada11aac28f0850f0e485acacf34e7eb81aa19.tar.gz rails-e8ada11aac28f0850f0e485acacf34e7eb81aa19.tar.bz2 rails-e8ada11aac28f0850f0e485acacf34e7eb81aa19.zip |
Associations: DRY up the code which is generating conditions, and make it all use arel rather than SQL strings
Diffstat (limited to 'activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb')
-rw-r--r-- | activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb | 10 |
1 files changed, 6 insertions, 4 deletions
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 e17ac6f2cc..24871303eb 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 @@ -75,10 +75,12 @@ module ActiveRecord "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}" end - def construct_conditions - sql = "#{@owner.connection.quote_table_name @reflection.options[:join_table]}.#{@reflection.primary_key_name} = #{owner_quoted_id} " - sql << " AND (#{conditions})" if conditions - sql + def join_table + Arel::Table.new(@reflection.options[:join_table]) + end + + def construct_owner_conditions + super(join_table) end def construct_find_scope |