Revert "Merge pull request #8313 from alan/only_save_changed_has_one_objects"

This reverts commit 6e3ab3e1, reversing
changes made to 39e07b64.

Conflicts:
	activerecord/CHANGELOG.md
	activerecord/test/cases/autosave_association_test.rb
上级 9a976ab5
* Save `has_one` association even if the record doesn't changed.
Fixes #14407.
*Rafael Mendonça França*
* Use singular table name in generated migrations when
`ActiveRecord::Base.pluralize_table_names` is `false`.
......@@ -76,12 +82,6 @@
*Troy Kruthoff*, *Lachlan Sylvester*
* Only save has_one associations if record has changes.
Previously after save related callbacks, such as `#after_commit`, were triggered when the has_one
object did not get saved to the db.
*Alan Kennedy*
* Allow strings to specify the `#order` value.
Example:
......
......@@ -377,16 +377,15 @@ def save_collection_association(reflection)
def save_has_one_association(reflection)
association = association_instance_get(reflection.name)
record = association && association.load_target
if record && !record.destroyed?
autosave = reflection.options[:autosave]
if autosave && record.marked_for_destruction?
record.destroy
elsif autosave != false
else
key = reflection.options[:primary_key] ? send(reflection.options[:primary_key]) : id
if autosave != false && (autosave || new_record? || record_changed?(reflection, record, key))
if (autosave && record.changed_for_autosave?) || new_record? || record_changed?(reflection, record, key)
unless reflection.through_reflection
record[reflection.foreign_key] = key
end
......
......@@ -683,23 +683,10 @@ def save(*args)
end
end
@ship.pirate.catchphrase = "Changed Catchphrase"
assert_raise(RuntimeError) { assert !@pirate.save }
assert_not_nil @pirate.reload.ship
end
def test_should_save_changed_has_one_changed_object_if_child_is_saved
@pirate.ship.name = "NewName"
assert @pirate.save
assert_equal "NewName", @pirate.ship.reload.name
end
def test_should_not_save_changed_has_one_unchanged_object_if_child_is_saved
@pirate.ship.expects(:save).never
assert @pirate.save
end
# belongs_to
def test_should_destroy_a_parent_association_as_part_of_the_save_transaction_if_it_was_marked_for_destroyal
assert !@ship.pirate.marked_for_destruction?
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册