aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib')
-rwxr-xr-xactiverecord/lib/active_record/associations.rb12
-rw-r--r--activerecord/lib/active_record/associations/belongs_to_association.rb5
2 files changed, 12 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index 23ccb34cd2..b2a2ed6e11 100755
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -449,11 +449,13 @@ module ActiveRecord
module_eval do
before_save <<-EOF
association = instance_variable_get("@#{association_name}")
- if not association.nil? and association.new_record?
- association.save(true)
- self["#{association_class_primary_key_name}"] = association.id
- association.send(:construct_sql)
- end
+ if not association.nil?
+ if association.new_record?
+ association.save(true)
+ association.send(:construct_sql)
+ end
+ self["#{association_class_primary_key_name}"] = association.id if association.updated?
+ end
EOF
end
diff --git a/activerecord/lib/active_record/associations/belongs_to_association.rb b/activerecord/lib/active_record/associations/belongs_to_association.rb
index 60c31ce486..fd36c2d8ae 100644
--- a/activerecord/lib/active_record/associations/belongs_to_association.rb
+++ b/activerecord/lib/active_record/associations/belongs_to_association.rb
@@ -32,12 +32,17 @@ module ActiveRecord
@target = obj
@owner[@association_class_primary_key_name] = obj.id unless obj.new_record?
+ @updated = true
end
@loaded = true
return (@target.nil? ? nil : self)
end
+ def updated?
+ @updated
+ end
+
protected