Skip to content

Commit

Permalink
Minor refactor of Model::_deleteLinks to improve readability.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Jan 29, 2010
1 parent 2d81d25 commit 7cfb5ab
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions cake/libs/model/model.php
Expand Up @@ -1825,14 +1825,15 @@ function _deleteDependent($id, $cascade) {
*/
function _deleteLinks($id) {
foreach ($this->hasAndBelongsToMany as $assoc => $data) {
$records = $this->{$data['with']}->find('all', array(
'conditions' => array_merge(array($this->{$data['with']}->escapeField($data['foreignKey']) => $id)),
'fields' => $this->{$data['with']}->primaryKey,
$joinModel = $data['with'];
$records = $this->{$joinModel}->find('all', array(
'conditions' => array_merge(array($this->{$joinModel}->escapeField($data['foreignKey']) => $id)),
'fields' => $this->{$joinModel}->primaryKey,
'recursive' => -1
));
if (!empty($records)) {
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]);
}
}
}
Expand Down

0 comments on commit 7cfb5ab

Please sign in to comment.