$config * @return void */ public function initialize(array $config): void { $this->hasMany('Articles'); } /** * @param \Cake\ORM\Query\SelectQuery $query * @param int|null $authorId * @return \Cake\ORM\Query\SelectQuery */ public function findByAuthor(SelectQuery $query, ?int $authorId = null): SelectQuery { if ($authorId !== null) { $query->where(['Articles.id' => $authorId]); } return $query; } /** * Finder that applies a formatter to test dirty associations * * @param \Cake\ORM\Query\SelectQuery $query The query * @param array $options The options * @return \Cake\ORM\Query\SelectQuery */ public function findFormatted(SelectQuery $query, array $options = []): SelectQuery { return $query->formatResults(function ($results) { return $results->map(function ($author) { $author->formatted = $author->name . '!!'; return $author; }); }); } /** * Finder that accepts an option via a typed parameter. * * @param \Cake\ORM\Query\SelectQuery $query The query * @param int $id Author ID * @return \Cake\ORM\Query\SelectQuery */ public function findWithIdArgument(SelectQuery $query, int $id): SelectQuery { return $query->where(['id' => $id]); } }