class Parent
has_one :child
end
class Child
belongs_to :parent
end
In this situation, use parent.build_child
to build child
from the existing parent
.
Normally, I thought that the DB record would not be rewritten just by building, but if you run this build when parent.child
already exists, the original child
will be Note that it will be built after being DELETEd
In the first place, when an existing association exists, I don't think that build will form an action to run, but when the DB is directly rewritten and the child model has already been created, there is no destroy. This is a phenomenon that I noticed when the record disappeared.
Because it was a story that did not get caught even if I googled
Recommended Posts