aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-06-17 10:08:41 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-06-17 10:08:41 +0000
commitd808cd4582d407a7b0dae93ee94da6fbc8cd0c2b (patch)
tree6c261fb210258a306734601c3d71d85cd751fa77 /activerecord/lib/active_record/associations.rb
parentef141e8536dd454ed532b62c4c8b04015269aece (diff)
downloadrails-d808cd4582d407a7b0dae93ee94da6fbc8cd0c2b.tar.gz
rails-d808cd4582d407a7b0dae93ee94da6fbc8cd0c2b.tar.bz2
rails-d808cd4582d407a7b0dae93ee94da6fbc8cd0c2b.zip
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
Diffstat (limited to 'activerecord/lib/active_record/associations.rb')
-rwxr-xr-xactiverecord/lib/active_record/associations.rb6
1 files changed, 5 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index 65549aca0c..610f1e3667 100755
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -671,7 +671,7 @@ module ActiveRecord
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 @@ module ActiveRecord
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