-
Notifications
You must be signed in to change notification settings - Fork 35
Description
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');
[...]