Skip to content

Commit

Permalink
Refactored the filterResults again. Now this method not call the call…
Browse files Browse the repository at this point in the history
…back afterFind when model is Model.
  • Loading branch information
jrbasso committed Feb 26, 2011
1 parent 34b4ff9 commit 63d700a
Showing 1 changed file with 26 additions and 19 deletions.
45 changes: 26 additions & 19 deletions cake/libs/model/datasources/dbo_source.php
Expand Up @@ -1128,29 +1128,36 @@ public function read($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()) {
$filtering = array();
$_filtered = array_flip($filtered);

foreach ($results as &$result) {
if (is_array($result)) {
if (!isset($keys)) {
$keys = array_keys($result);
}
foreach ($keys as $className) {
if ($model->alias !== $className && !isset($_filtered[$className])) {
$filtering[] = $className;
static $haveCallback = array();

if (isset($model->{$className}) && is_object($model->{$className})) {
$data = $model->{$className}->afterFind(array(array($className => $result[$className])), false);
}
if (isset($data[0][$className])) {
$result[$className] = $data[0][$className];
}
}
$current = current($results);
if (!is_array($current)) {
return array();
}
$keys = array_diff(array_keys($current), $filtered, array($model->alias));
$filtering = array();
foreach ($keys as $className) {
if (!isset($model->{$className}) || !is_object($model->{$className})) {
continue;
}
$linkedModel = $model->{$className};
$linkedClass = get_class($linkedModel);
if (!isset($haveCallback[$linkedClass])) {
$ref = new ReflectionClass($linkedModel);
$haveCallback[$linkedClass] = $ref->getMethod('afterFind')->class !== 'Model';
}
if ($haveCallback[$linkedClass] !== true) {
continue;
}
$filtering[] = $className;
foreach ($results as &$result) {
$data = $linkedModel->afterFind(array(array($className => $result[$className])), false);
if (isset($data[0][$className])) {
$result[$className] = $data[0][$className];
}
}
}
return array_unique($filtering);
return $filtering;
}

/**
Expand Down

0 comments on commit 63d700a

Please sign in to comment.