public function cascadeDelete(Association $association, EntityInterface $entity, array $options = [])
    {
        if (!$association->getDependent()) {
            return true;
        }
        $table = $association->getTarget();
        $foreignKey = array_map([$association, 'aliasField'], (array)$association->getForeignKey());
        $bindingKey = (array)$association->getBindingKey();
        $conditions = array_combine($foreignKey, $entity->extract($bindingKey));

        if ($association->getCascadeCallbacks()) {
            foreach ($association->find()->where($conditions)->all()->toList() as $related) {
                $table->delete($related, $options);
            }

            return true;
        }
        $conditions = array_merge($conditions, $association->getConditions());

        return (bool)$table->deleteAll($conditions);
    }
public function cascadeDelete(Association $association, EntityInterface $entity, array $options = [])
    {
        if (!$association->getDependent()) {
            return true;
        }
        $table = $association->getTarget();
        $foreignKey = array_map([$association, 'aliasField'], (array)$association->getForeignKey());
        $bindingKey = (array)$association->getBindingKey();
        $conditions = array_combine($foreignKey, $entity->extract($bindingKey));

        if ($association->getCascadeCallbacks()) {
            foreach ($association->find()->where($conditions)->all()->toList() as $related) {
                $table->delete($related, $options);
            }

            return true;
        }
        $conditions = array_merge($conditions, $association->getConditions());

        return (bool)$table->deleteAll($conditions);
    }
public function cascadeDelete ( Association $ association , EntityInterface $ entity , array $ options = [ ] ) { if ( ! $ association -> getDependent ( ) ) { return true ; } $ table = $ association -> getTarget ( ) ; $ foreignKey = array_map ( [ $ association , 'aliasField' ] , ( array ) $ association -> getForeignKey ( ) ) ; $ bindingKey = ( array ) $ association -> getBindingKey ( ) ; $ conditions = array_combine ( $ foreignKey , $ entity -> extract ( $ bindingKey ) ) ; if ( $ association -> getCascadeCallbacks ( ) ) { foreach ( $ association -> find ( ) -> where ( $ conditions ) -> all ( ) -> toList ( ) as $ related ) { $ table -> delete ( $ related , $ options ) ; } return true ; } $ conditions = array_merge ( $ conditions , $ association -> getConditions ( ) ) ; return ( bool ) $ table -> deleteAll ( $ conditions ) ; }
Cascade a delete to remove dependent records.

This method does nothing if the association is not dependent.

@param \Cake\ORM\Association $association The association callbacks are being cascaded on.
@param \Cake\Datasource\EntityInterface $entity The entity that started the cascaded delete.
@param array $options The options for the original delete.
@return bool Success.
Cascade a delete to remove dependent records .