[BUG]: SoftDelete
behavior tries to create new record of belongsTo
relationship
#16453
Labels
SoftDelete
behavior tries to create new record of belongsTo
relationship
#16453
Describe the bug
When trying to delete a model record with
SoftDelete
behavior enabled on the model, Phalcon attempts to re-create another model record that the deleted recordbelongsTo
.To Reproduce
Foo
andBar
);Foo
and validate it usingValidator\Uniqueness
;Foo
andBar
:Foo::initialize()
:$this->hasMany('id', 'Bar', 'foo_id', ["alias" => "Bars"]);
Bar::initialize()
:$this->belongsTo('foo_id', 'Foo', 'id');
SoftDelete
behavior forBar
using the fieldBar::deleted
;Foo
and save it, then create one record ofBar
withfoo_id
refering to the recently createdFoo
record and save it;Bar
record using itsdelete()
method.During the deletion process, the uniqueness validator of
Foo
fails, as Phalcon is trying to create a new record of a model using the data of the already existing record. It's not evident to me why Phalcon wants to touch any related records at all during soft delete, but here's the output ofdebug_print_backtrace()
as called fromFoo::validation()
:Calling the
save()
method of theBar
instance directly does not produce this issue.Expected behavior
I would not expect related records to be re-saved during a soft delete, but even if they do get re-saved, it should be an update operation, not a create operation.
Details
The text was updated successfully, but these errors were encountered: