You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For a Twinnable HasMany relation you can configure the cascade_delete by setting true or false.
With cascade_delete set to false there are 2 possible behaviours :
if key_to is not a common field on the target model, the item will be soft deleted (key_to set to 0), the items in the others contexts won't be deleted.
if key_to is a common field on the target model, the item and the items in the others contexts will be soft deleted (the key_to is set to 0) .
But with cascade_delete set to true there is only one behaviour :
regardless whether the key_to is a common field or not, the item will be hard deleted (removed from database), and items in the others contexts won't be deleted.
... instead it should be :
if key_to is not a common field on the target model, the item will be hard deleted (removed from database), the items in the others contexts won't be deleted.
if key_to is a common field on the target model, the item and the items in the others contexts will be hard deleted (removed from database).
To fix this issue we will have to write a custom save method on Nos\Orm_Twinnable_HasMany instead of using the save method of the parent class Orm\HasMany.
Here is the part of the save method that hard deletes the related item :
$model_from->unfreeze();
// Deletes the items in the other contexts if key_to is a common fieldif (check_if_key_to_is_a_common_field()) { // @todoforeach ($obj->find_other_contexts() as$other_obj) {
$other_obj->delete();
}
}
// Deletes the item in the current context$obj->delete();
$model_from->freeze();
Will try to start a pull request when I'll have time.
In the meantime if you need to remove the items in all the contexts, use the soft delete (cascade_delete set to false).
Edit: updated patch code
The text was updated successfully, but these errors were encountered:
For a Twinnable HasMany relation you can configure the
cascade_delete
by settingtrue
orfalse
.With
cascade_delete
set tofalse
there are 2 possible behaviours :key_to
is not a common field on the target model, the item will be soft deleted (key_to
set to 0), the items in the others contexts won't be deleted.key_to
is a common field on the target model, the item and the items in the others contexts will be soft deleted (thekey_to
is set to 0) .But with
cascade_delete
set totrue
there is only one behaviour :key_to
is a common field or not, the item will be hard deleted (removed from database), and items in the others contexts won't be deleted.... instead it should be :
key_to
is not a common field on the target model, the item will be hard deleted (removed from database), the items in the others contexts won't be deleted.key_to
is a common field on the target model, the item and the items in the others contexts will be hard deleted (removed from database).To fix this issue we will have to write a custom
save
method onNos\Orm_Twinnable_HasMany
instead of using thesave
method of the parent classOrm\HasMany
.Here is the part of the
save
method that hard deletes the related item :It could be patched this way :
Will try to start a pull request when I'll have time.
In the meantime if you need to remove the items in all the contexts, use the soft delete (
cascade_delete
set tofalse
).Edit: updated patch code
The text was updated successfully, but these errors were encountered: