/** * Handles beforeFind event * * @param Model $model Model * @param array $query Query * @return array Modified query */ public static function handleBeforeFind(Model $model, $query) { if (is_array($query)) { if (isset($query['contain'])) { if ($query['contain'] === false) { $query['recursive'] = -1; } else { $EagerLoader = new EagerLoader(); $query = $EagerLoader->transformQuery($model, $query); self::$handlers[$EagerLoader->id] = $EagerLoader; if (count(self::$handlers) > 1000) { $id = min(self::ids()); unset(self::$handlers[$id]); } } } } return $query; }
/** * afterFind callback * * @param Model $model Model using the behavior * @param array $results The results of the find operation * @param bool $primary Whether this model is being queried directly * @return array */ public function afterFind(Model $model, $results, $primary = false) { return EagerLoader::handleAfterFind($model, $results); }
/** * Tests that an exception occurs if invalid ID specified * * @return void * * @expectedException UnexpectedValueException * @expectedExceptionMessage EagerLoader "foo" is not found */ public function testNotFound() { $User = ClassRegistry::init('User'); EagerLoader::handleAfterFind($User, array(array('EagerLoaderModel' => array('id' => 'foo')))); }