From a2f26b971bf61263582604ad7e1af14b9566949e Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sat, 18 Jun 2005 05:28:59 +0000 Subject: Fixed that adding a record to a has_and_belongs_to collection would always save it -- now it only saves if its a new record #1203 [Alisdair McDiarmid] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1453 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- .../active_record/associations/has_and_belongs_to_many_association.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'activerecord/lib/active_record') 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 42a4f3495d..b34574161f 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 @@ -104,7 +104,9 @@ module ActiveRecord end def insert_record(record) - return false unless record.save + if record.new_record? + return false unless record.save + end if @options[:insert_sql] @owner.connection.execute(interpolate_sql(@options[:insert_sql], record)) -- cgit v1.2.3