hasMany('articles'); } public function findByAuthor(Query $query, array $options = []) { if (isset($options['author_id'])) { $query->where(['Articles.id' => $options['author_id']]); } return $query; } /** * Finder that applies a formatter to test dirty associations * * @param \Cake\ORM\Query $query The query * @param array $options The options * @return \Cake\ORM\Query */ public function findFormatted(Query $query, array $options = []) { return $query->formatResults(function ($results) { return $results->map(function ($author) { $author->formatted = $author->name . '!!'; return $author; }); }); } }