Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cascadeDeleting not working with emptyTrash() #56

Open
frandss opened this issue Aug 9, 2022 · 1 comment
Open

cascadeDeleting not working with emptyTrash() #56

frandss opened this issue Aug 9, 2022 · 1 comment

Comments

@frandss
Copy link

frandss commented Aug 9, 2022

I'm using CakePHP 3.10.4, Compras (purchases) -> hasMany -> Carritos (cart items) -> hasMany -> Entradas (show tickets)

If any purchase is deleted "soft delete with delete()", purchase, cart items and tickets update deleted field correctly.
Code:
$entity = $this->Compras->findById($id)->find('translations')->first();
$this->Compras->delete($entity);

Later, if a deleted purchase is deleted "hard delete with emptyTrash()", only purchase is removed from database.
Code:
$entity = $this->Compras->find('onlyTrashed')->find('translations')->where(['Compras.id' => $id])->first();
$this->Compras->emptyTrash($entity);

Additional data:
ComprasTable:
[...]
$this->hasMany('Ventas.Carritos')
->setForeignKey('compra_id')
->setDependent(true)
->setCascadeCallbacks(true)
->setSort(['Carritos.producto_id' => 'asc', 'Carritos.modelo_id' => 'asc', 'Carritos.experiencia_id' => 'asc', 'Carritos.cantidad' => 'asc']);
[...]

CarritosTable:
[...]
$this->belongsTo('Ventas.Compras')
->setFinder('withTrashed');
$this->hasMany('Ticketing.Entradas')
->setForeignKey('carrito_id')
->setDependent(true)
->setCascadeCallbacks(true);
[...]

EntradasTable:
[...]
$this->belongsTo('Ventas.Carritos')
->setFinder('withTrashed');
[...]

@ADmad
Copy link
Member

ADmad commented Aug 9, 2022

emptyTrash() uses Table::deleteAll() which does not use callbacks. You can submit a pull request if you like adding a $cascade argument to the method and updating internals accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants