/** * BeforeFind callback - converts entities based on STI tables. * * @param \Cake\Event\Event $event Event. * @param \Cake\Database\Query $query Query. * @param \ArrayAccess $options Options. * @return void */ public function beforeFind(Event $event, Query $query, ArrayAccess $options) { if (!$query->hydrate()) { return; } $query->formatResults(function ($results) { return $results->map(function ($row) { if ($row instanceof CopyableEntityInterface) { $table = $this->stiTable($row); $entityClass = $table->entityClass(); $row = new $entityClass($row->copyProperties(), ['markNew' => $row->isNew(), 'markClean' => true, 'guard' => false, 'source' => $table->registryAlias()]); } return $row; }); }); }