diff options
author | Emilio Tagua <miloops@gmail.com> | 2009-08-18 19:38:34 -0300 |
---|---|---|
committer | Emilio Tagua <miloops@gmail.com> | 2009-08-18 19:38:34 -0300 |
commit | c1f833dff47eb5c0a74eb80f011597c7130bc8d7 (patch) | |
tree | fed4d983f204770b65844a0e600fe23d6ce74ffa /activerecord/lib | |
parent | 0abba2813be52cc8f8ff2544f8a3b18b5083be53 (diff) | |
download | rails-c1f833dff47eb5c0a74eb80f011597c7130bc8d7.tar.gz rails-c1f833dff47eb5c0a74eb80f011597c7130bc8d7.tar.bz2 rails-c1f833dff47eb5c0a74eb80f011597c7130bc8d7.zip |
habtm delete method integrated with ARel.
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb | 9 |
1 files changed, 5 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 d91c555dad..a1aac3ead5 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 @@ -34,7 +34,7 @@ module ActiveRecord options[:readonly] = finding_with_ambiguous_select?(options[:select] || @reflection.options[:select]) options[:select] ||= (@reflection.options[:select] || '*') end - + def count_records load_target.size end @@ -85,9 +85,10 @@ module ActiveRecord if sql = @reflection.options[:delete_sql] records.each { |record| @owner.connection.delete(interpolate_sql(sql, record)) } else - ids = quoted_record_ids(records) - sql = "DELETE FROM #{@owner.connection.quote_table_name @reflection.options[:join_table]} WHERE #{@reflection.primary_key_name} = #{owner_quoted_id} AND #{@reflection.association_foreign_key} IN (#{ids})" - @owner.connection.delete(sql) + relation = arel_table(@reflection.options[:join_table]) + relation.conditions(relation[@reflection.primary_key_name].eq(@owner.id). + and(Arel::In.new(relation[@reflection.association_foreign_key], records.map(&:id))) + ).delete end end |