Merge pull request #13048 from garethellis36/13046

Separates derivation of conditions for cascaded deletion of HABTM records to a protected method #13046
This commit is contained in:
Mark Story 2019-03-14 09:19:46 -04:00 committed by GitHub
commit 4fd57b86ca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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.
*