Skip to content

Commit

Permalink
Fixed duplication of Model's afterFind callback in HABTM relation and…
Browse files Browse the repository at this point in the history
… content of array passed to that callback [ticket 3970]
  • Loading branch information
k-halaburda committed Aug 9, 2013
1 parent 49d66af commit c033df3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 82 deletions.
79 changes: 0 additions & 79 deletions app/Config/database.php.default

This file was deleted.

12 changes: 9 additions & 3 deletions lib/Cake/Model/Datasource/DboSource.php
Expand Up @@ -1112,7 +1112,7 @@ public function read(Model $model, $queryData = array(), $recursive = null) {
$db->queryAssociation($model, $linkModel, $type, $assoc, $assocData, $array, true, $resultSet, $model->recursive - 1, $stack);
unset($db);

if ($type === 'hasMany') {
if ($type === 'hasMany' || $type === 'hasAndBelongsToMany') {
$filtered[] = $assoc;
}
}
Expand All @@ -1138,7 +1138,10 @@ public function read(Model $model, $queryData = array(), $recursive = null) {
* @return array Array of results that have been filtered through $model->afterFind
*/
protected function _filterResults(&$results, Model $model, $filtered = array()) {
$current = reset($results);
if (!is_array($results)) {
return array();
}
$current = reset($results);
if (!is_array($current)) {
return array();
}
Expand Down Expand Up @@ -1252,6 +1255,9 @@ public function queryAssociation(Model $model, &$linkModel, $type, $association,
} else {
$fetch = null;
}
if ($queryData['callbacks'] === true || $queryData['callbacks'] === 'after') {
$this->_filterResults($fetch, $model);
}
}

$modelAlias = $model->alias;
Expand Down Expand Up @@ -1312,7 +1318,7 @@ public function queryAssociation(Model $model, &$linkModel, $type, $association,
} else {
$this->_mergeAssociation($row, $fetch, $association, $type, $selfJoin);
}
if (isset($row[$association])) {
if (isset($row[$association]) && $type !== 'hasAndBelongsToMany') {
$row[$association] = $linkModel->afterFind($row[$association], false);
}
} else {
Expand Down

0 comments on commit c033df3

Please sign in to comment.