Nextras\Orm\Mapper\Memory\RelationshipMapperManyHasMany::getIterator PHP Метод

getIterator() публичный Метод

public getIterator ( Nextras\Orm\Entity\IEntity $parent, Nextras\Orm\Collection\ICollection $collection )
$parent Nextras\Orm\Entity\IEntity
$collection Nextras\Orm\Collection\ICollection
    public function getIterator(IEntity $parent, ICollection $collection)
    {
        if ($this->metadata->relationship->isMain) {
            $relationshipData = $this->mapper->getRelationshipDataStorage($this->metadata->name);
            $id = $parent->getValue('id');
            $ids = isset($relationshipData[$id]) ? array_keys($relationshipData[$id]) : [];
        } else {
            $ids = [];
            $parentId = $parent->getValue('id');
            $relationshipData = $this->mapper->getRelationshipDataStorage($this->metadata->relationship->property);
            foreach ($relationshipData as $id => $parentIds) {
                if (isset($parentIds[$parentId])) {
                    $ids[] = $id;
                }
            }
        }
        $data = $collection->findBy(['id' => $ids])->fetchAll();
        return new EntityIterator($data);
    }