diff options
author | Michael Koziarski <michael@koziarski.com> | 2007-10-10 06:45:13 +0000 |
---|---|---|
committer | Michael Koziarski <michael@koziarski.com> | 2007-10-10 06:45:13 +0000 |
commit | 1c881ca5bfc36689b4918edf497b38d24df7b57e (patch) | |
tree | d2b70c2ea0ffeafb40d194129e9cdee8f2bd2481 /activerecord/lib | |
parent | 4db4661a67529d6238ed255cd51d42d6f68306e1 (diff) | |
download | rails-1c881ca5bfc36689b4918edf497b38d24df7b57e.tar.gz rails-1c881ca5bfc36689b4918edf497b38d24df7b57e.tar.bz2 rails-1c881ca5bfc36689b4918edf497b38d24df7b57e.zip |
Ensure that 'autosaving' works when associations aren't loaded [Bryan Helmkamp] References #8713
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7824 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib')
-rwxr-xr-x | activerecord/lib/active_record/associations.rb | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index 1a4a46eb3d..ab4e02f86c 100755 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -1072,12 +1072,15 @@ module ActiveRecord after_callback = <<-end_eval association = instance_variable_get("@#{association_name}") - if association.respond_to?(:loaded?) && association.loaded? - if @new_record_before_save - records_to_save = association - else - records_to_save = association.select { |record| record.new_record? } - end + records_to_save = if @new_record_before_save + association + elsif association.respond_to?(:loaded?) && association.loaded? + association.select { |record| record.new_record? } + else + [] + end + + if !records_to_save.blank? 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 |