» API Reference » ORM\Relation\ParentChildren
ORM\Relation\ParentChildren
Table of Contents
Abstract
Extends: ORM\Relation\OneToMany
A parent to children (many)
Methods
ORM\Relation\ParentChildren::__construct
public function __construct(
string $class,
string $opponent,
\ORM\EntityFetcher\FilterInterface[]|callable[] $filters = [],
)
Owner constructor.
Parameters
ORM\Relation\ParentChildren::__construct
↑ top
ORM\Relation\ParentChildren::addJoin
public function addJoin(
\ORM\EntityFetcher $fetcher,
mixed $join,
mixed $alias,
): mixed
{@inheritdoc}
Parameters
ORM\Relation\ParentChildren::addJoin
↑ top
public function addRelated(
\ORM\Entity $self,
\ORM\Entity[] $entities,
\ORM\EntityManager $entityManager,
): mixed
Add $entities to association table
Parameters
ORM\Relation\ParentChildren::addRelated
↑ top
ORM\Relation\ParentChildren::buildTree
public function buildTree(\ORM\Entity $entities): \ORM\Entity[]
Set all children and return an array containing the root elements
This method expects you to pass all elements of a branch. Keep in mind that that the array you
are getting is not necessarily from the same parent if you are not passing all elements of a branch.
Example of this issue:
Elements passed ['1.', '1.2.', '1.3.', '3.5.', '4.']
(each element is represented by its materialized path).
As ‘3.’ is not passed, ‘3.5.’ seems to be the root element resulting in the following tree:
[
[path => '1.', children => [['path' => '1.2.'],['path' => '1.3.']]],
[path => '3.5.'],
[path => '4.'],
]
Example usage when you are using materialized paths:
$children = $em->fetch('Category::class')->where('path', 'LIKE', '3.5._%')->all();
$treeOf35 = Category::getRelation('children')->buildTree(...$children);
Parameters
ORM\Relation\ParentChildren::buildTree
↑ top
ORM\Relation\ParentChildren::createRelation
public static function createRelation(
string $parent,
string $name,
array $relDef,
): \ORM\Relation
Factory for relation definition object
Parameters
Parameter |
Type |
Description |
$parent |
string |
|
$name |
string |
|
$relDef |
array |
|
ORM\Relation\ParentChildren::createRelation
↑ top
public function deleteRelated(
\ORM\Entity $self,
\ORM\Entity[] $entities,
\ORM\EntityManager $entityManager,
): mixed
Delete $entities from association table
Parameters
ORM\Relation\ParentChildren::deleteRelated
↑ top
ORM\Relation\ParentChildren::eagerLoad
public function eagerLoad(\ORM\EntityManager $em, \ORM\Entity $entities): mixed
Load this relation for all $entities with one query
Parameters
ORM\Relation\ParentChildren::eagerLoad
↑ top
ORM\Relation\ParentChildren::fetch
public function fetch(
\ORM\Entity $self,
\ORM\EntityManager $entityManager,
): mixed
Fetch the relation
Parameters
ORM\Relation\ParentChildren::fetch
↑ top
ORM\Relation\ParentChildren::fetchAll
public function fetchAll(
\ORM\Entity $self,
\ORM\EntityManager $entityManager,
): \ORM\Entity[]|\ORM\Entity
Fetch all from the relation
Runs fetch and returns EntityFetcher::all() if a Fetcher is returned.
Parameters
ORM\Relation\ParentChildren::fetchAll
↑ top
ORM\Relation\ParentChildren::fromShort
public static function fromShort(mixed $parent, array $short): mixed
{@inheritDoc}
Static |
|
This method is static. |
Returns |
mixed |
|
Parameters
Parameter |
Type |
Description |
$parent |
mixed |
|
$short |
array |
|
ORM\Relation\ParentChildren::fromShort
↑ top
public function setRelated(
\ORM\Entity $self,
\ORM\Entity|null $entity = null,
): mixed
Set the relation to $entity
Parameters
ORM\Relation\ParentChildren::setRelated
↑ top