Permalink
Browse files

Fixed saving of in-memory association structures to happen as a after…

…_create/after_update callback instead of after_save -- that way you can add new associations in after_create/after_update callbacks without getting them saved twice

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1448 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent ef141e8 commit d808cd4582d407a7b0dae93ee94da6fbc8cd0c2b @dhh dhh committed Jun 17, 2005
Showing with 7 additions and 1 deletion.
  1. +2 −0 activerecord/CHANGELOG
  2. +5 −1 activerecord/lib/active_record/associations.rb
View
@@ -1,5 +1,7 @@
*SVN*
+* Fixed saving of in-memory association structures to happen as a after_create/after_update callback instead of after_save -- that way you can add new associations in after_create/after_update callbacks without getting them saved twice
+
* Allow any Enumerable, not just Array, to work as bind variables #1344 [Jeremy Kemper]
* Added actual database-changing behavior to collection assigment for has_many and has_and_belongs_to_many #1425 [Sebastian Kanthak].
@@ -671,7 +671,7 @@ def add_multiple_associated_save_callbacks(association_name)
end
module_eval do
- after_save <<-end_eval
+ after_callback = <<-end_eval
association = instance_variable_get("@#{association_name}")
if association.respond_to?(:loaded?)
if @new_record_before_save
@@ -683,6 +683,10 @@ def add_multiple_associated_save_callbacks(association_name)
association.send(:construct_sql) # reconstruct the SQL queries now that we know the owner's id
end
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)
end
end

0 comments on commit d808cd4

Please sign in to comment.