From c14782305bc6f4e9ea72c99654740c0979ae46ff Mon Sep 17 00:00:00 2001 From: Gareth Ellis Date: Thu, 14 Mar 2019 10:20:23 +0000 Subject: [PATCH] Separates derivation of conditions for cascaded deletion of HABTM records to a protected method #13046 --- lib/Cake/Model/Model.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Model/Model.php b/lib/Cake/Model/Model.php index a854e644d..6f14d785a 100644 --- a/lib/Cake/Model/Model.php +++ b/lib/Cake/Model/Model.php @@ -2801,7 +2801,7 @@ class Model extends CakeObject implements CakeEventListener { list(, $joinModel) = pluginSplit($data['with']); $Model = $this->{$joinModel}; $records = $Model->find('all', array( - 'conditions' => array($Model->escapeField($data['foreignKey']) => $id), + 'conditions' => $this->_getConditionsForDeletingLinks($Model, $id, $data), 'fields' => $Model->primaryKey, 'recursive' => -1, 'callbacks' => false @@ -2815,6 +2815,19 @@ class Model extends CakeObject implements CakeEventListener { } } +/** + * Returns the conditions to be applied to Model::find() when determining which HABTM records should be deleted via + * Model::_deleteLinks() + * + * @param Model $Model HABTM join model instance + * @param mixed $id The ID of the primary model which is being deleted + * @param array $relationshipConfig The relationship config defined on the primary model + * @return array + */ + protected function _getConditionsForDeletingLinks(Model $Model, $id, array $relationshipConfig) { + return array($Model->escapeField($relationshipConfig['foreignKey']) => $id); + } + /** * Deletes multiple model records based on a set of conditions. *