diff options
author | Florian Weber <csshsh@gmail.com> | 2005-11-23 21:03:25 +0000 |
---|---|---|
committer | Florian Weber <csshsh@gmail.com> | 2005-11-23 21:03:25 +0000 |
commit | c66ac2102be2d7a53872c7bb96939f616275010e (patch) | |
tree | 039951a6c2afcc30d5ebafd665d0d4df5d20993f /activerecord/lib | |
parent | 202e4208c4d26f05ea856dbd57f4843ee3a7db29 (diff) | |
download | rails-c66ac2102be2d7a53872c7bb96939f616275010e.tar.gz rails-c66ac2102be2d7a53872c7bb96939f616275010e.tar.bz2 rails-c66ac2102be2d7a53872c7bb96939f616275010e.zip |
Fixed bug where using update_attribute after pushing a record to a habtm association of the object caused duplicate rows in the join table. #2888
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3167 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib')
-rwxr-xr-x | activerecord/lib/active_record/associations.rb | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index d4b7f88907..70bc4a4d65 100755 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -800,6 +800,7 @@ module ActiveRecord after_callback = <<-end_eval association = instance_variable_get("@#{association_name}") + if association.respond_to?(:loaded?) if @new_record_before_save records_to_save = association @@ -809,8 +810,11 @@ module ActiveRecord records_to_save.each { |record| association.send(:insert_record, record) } association.send(:construct_sql) # reconstruct the SQL queries now that we know the owner's id end + + @new_record_before_save = false + true end_eval - + # Doesn't use after_save as that would save associations added in after_create/after_update twice after_create(after_callback) after_update(after_callback) |