Skip to content

cascadeDeleting not working with emptyTrash() #56

@frandss

Description

@frandss

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');
[...]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions