class ReferencePrimer (View source)

The ReferencePrimer is responsible for priming reference relationships.

Priming a field mapped as either reference-one or reference-many will load the referenced document(s) eagerly and avoid individual lazy loading through proxy object initialization.

Priming can only be used for the owning side side of a relationship, since the referenced identifiers are not immediately available on an inverse side.

Methods

__construct(DocumentManager $dm, UnitOfWork $uow)

Constructor.

primeReferences(ClassMetadata $class, array|Traversable $documents, string $fieldName, array $hints = array(), callable $primer = null)

Prime references within a mapped field of one or more documents.

Details

__construct(DocumentManager $dm, UnitOfWork $uow)

Constructor.

Parameters

DocumentManager $dm
UnitOfWork $uow

primeReferences(ClassMetadata $class, array|Traversable $documents, string $fieldName, array $hints = array(), callable $primer = null)

Prime references within a mapped field of one or more documents.

If a $primer callable is provided, it should have the same signature as the default primer defined in the constructor. If $primer is not callable, the default primer will be used.

Parameters

ClassMetadata $class Class metadata for the document
array|Traversable $documents Documents containing references to prime
string $fieldName Field name containing references to prime
array $hints UnitOfWork hints for priming queries
callable $primer Optional primer callable

Exceptions

InvalidArgumentException If the mapped field is not the owning side of a reference relationship.
InvalidArgumentException If $primer is not callable
LogicException If the mapped field is a simple reference and is missing a target document class.