提交 9991f14f 编写于 作者: M Mehmet Emin İNAÇ

Fix for has_and_belongs_to_many & has_many_through associations while partial_writes is false

This will fix #19663

Also with this fix, active record does not fire unnecassary update queries while partial_writes is true
上级 7ee20020
* Improved partial writes with HABTM and has many through associations
to fire database query only if relation has been changed.
Fixes #19663.
*Mehmet Emin İNAÇ*
* Rework `ActiveRecord::Relation#last`
1. Never perform additional SQL on loaded relation
......@@ -18,7 +25,6 @@
*Bogdan Gusiev*
* Allow `joins` to be unscoped.
Closes #13775.
......
......@@ -86,7 +86,10 @@ def through_scope_attributes
end
def save_through_record(record)
build_through_record(record).save!
association = build_through_record(record)
if association.changed?
association.save!
end
ensure
@through_records.delete(record.object_id)
end
......
......@@ -982,4 +982,17 @@ def test_has_and_belongs_to_many_is_useable_with_belongs_to_required_by_default
Project.first.developers_required_by_default.create!(name: "Sean", salary: 50000)
end
end
def test_has_and_belongs_to_many_while_partial_writes_false
begin
original_partial_writes = ActiveRecord::Base.partial_writes
ActiveRecord::Base.partial_writes = false
developer = Developer.new(name: "Mehmet Emin İNAÇ")
developer.projects << Project.new(name: "Bounty")
assert developer.save
ensure
ActiveRecord::Base.partial_writes = original_partial_writes
end
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册