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