mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 11:06:15 +00:00
Minor refactor of Model::_deleteLinks to improve readability.
This commit is contained in:
parent
2d81d25f41
commit
7cfb5aba8d
1 changed files with 5 additions and 4 deletions
|
@ -1825,14 +1825,15 @@ class Model extends Overloadable {
|
||||||
*/
|
*/
|
||||||
function _deleteLinks($id) {
|
function _deleteLinks($id) {
|
||||||
foreach ($this->hasAndBelongsToMany as $assoc => $data) {
|
foreach ($this->hasAndBelongsToMany as $assoc => $data) {
|
||||||
$records = $this->{$data['with']}->find('all', array(
|
$joinModel = $data['with'];
|
||||||
'conditions' => array_merge(array($this->{$data['with']}->escapeField($data['foreignKey']) => $id)),
|
$records = $this->{$joinModel}->find('all', array(
|
||||||
'fields' => $this->{$data['with']}->primaryKey,
|
'conditions' => array_merge(array($this->{$joinModel}->escapeField($data['foreignKey']) => $id)),
|
||||||
|
'fields' => $this->{$joinModel}->primaryKey,
|
||||||
'recursive' => -1
|
'recursive' => -1
|
||||||
));
|
));
|
||||||
if (!empty($records)) {
|
if (!empty($records)) {
|
||||||
foreach ($records as $record) {
|
foreach ($records as $record) {
|
||||||
$this->{$data['with']}->delete($record[$this->{$data['with']}->alias][$this->{$data['with']}->primaryKey]);
|
$this->{$joinModel}->delete($record[$this->{$joinModel}->alias][$this->{$joinModel}->primaryKey]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue