/** * Parser callback for onAfterHasManyThrough event * * @param HasManyThrough $relation The data structure * @param LocatorInterface $locator The XML description file locator * * @return void */ public function handleHasManyThrough(HasManyThrough $relation, LocatorInterface $locator) { $basename = $this->getBasename($relation->name); $this->reflector->addHandler($basename, function () use($relation, $locator) { $id = $this->reflector->getId(); if (empty($id)) { return null; } $basename = $this->getBasename($relation->name); // Records from {$relation->entity} with {$relation->reference} IN ids from {$relation->joinTable} with {$relation->joinRef}={$id} $map = new Repository($relation->joinTable, $locator); $entries = $map->findAll()->with($relation->joinRef, Operator::EQUAL, $id)->get(); $repository = new Repository($relation->entity, $locator); $entities = $repository->findAll()->with($relation->reference, Operator::IN, $entries->getIds()); $this->reflector->addField(new Field(['name' => $basename, 'type' => 'relationData', 'value' => $entities])); return $entities; }); }