aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-02-14 11:51:56 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2011-02-14 11:51:56 -0800
commit0123ceb9cd1ae352308184852cae1edbd62155e1 (patch)
treee52d0c9c4fdca1f5e263e38faa10877eaa3190ec /activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb
parent6f4e3ffd0f42c92a00536e7e1356be3e8cf37639 (diff)
parentb9ea751d0e56bd00d341766977a607ed3f7ddd0f (diff)
downloadrails-0123ceb9cd1ae352308184852cae1edbd62155e1.tar.gz
rails-0123ceb9cd1ae352308184852cae1edbd62155e1.tar.bz2
rails-0123ceb9cd1ae352308184852cae1edbd62155e1.zip
Merge remote branch 'jonleighton/association_fixes'
* jonleighton/association_fixes: Add a transaction wrapper in add_to_target. This means that #build will now also use a transaction. IMO this is reasonable given that the before_add and after_add callbacks might do anything, and this great consistency allows us to abstract out the duplicate code from #build and #create. Inline ensure_owner_is_persisted! as it is only called from one place @target should always be an array Rename add_record_to_target_with_callbacks to add_to_target Don't pass the block through build_record Move create and create! next to build Get rid of create_record as it is not only used in one place Get rid of AssociationCollection#save_record Fix test/cases/connection_pool_test.rb for sqlite3 in-memory db Add interpolation of association conditions back in, in the form of proc { ... } rather than instance_eval-ing 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.rb12
1 files changed, 5 insertions, 7 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 b0ccab2de6..b9c9919e7a 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
@@ -11,13 +11,11 @@ module ActiveRecord
protected
- def insert_record(record, force = true, validate = true)
- if record.new_record?
- return false unless save_record(record, force, validate)
- end
+ def insert_record(record, validate = true)
+ return if record.new_record? && !record.save(:validate => validate)
if @reflection.options[:insert_sql]
- @owner.connection.insert(interpolate_sql(@reflection.options[:insert_sql], record))
+ @owner.connection.insert(interpolate(@reflection.options[:insert_sql], record))
else
stmt = join_table.compile_insert(
join_table[@reflection.foreign_key] => @owner.id,
@@ -27,7 +25,7 @@ module ActiveRecord
@owner.connection.insert stmt.to_sql
end
- true
+ record
end
def association_scope
@@ -42,7 +40,7 @@ module ActiveRecord
def delete_records(records, method)
if sql = @reflection.options[:delete_sql]
- records.each { |record| @owner.connection.delete(interpolate_sql(sql, record)) }
+ records.each { |record| @owner.connection.delete(interpolate(sql, record)) }
else
relation = join_table
stmt = relation.where(relation[@reflection.foreign_key].eq(@owner.id).