ResolveRelationsTrait
Table of Contents
Properties
- $em : EntityManagerInterface
Methods
- resolveRelations() : void
- bridgeScalarFkToAssociation() : void
- Fills a ManyToOne association from the value of the scalar foreign key that shares the same join column (typically `$menuId` and `menu`, `$pageId` and `page`). Does nothing when the association is not mapped in this entity variant or the scalar is missing or empty (null/0).
- linkOwnedCollections() : void
- Links the owning side of owned collections (cascade persist OneToMany, for example translations): sets the back-reference to the parent (`mappedBy`) on every child so that Doctrine writes the FK on flush. Without it newly hydrated children would be saved with a null foreign key (or the insert would fail).
- resolveFkIdentifierField() : string|null
- Finds the name of the identifier field of the target entity whose database column equals the join column of the back association (`mappedBy`), that is an identifier which is also a foreign key to the parent. Returns null when there is none.
Properties
$em
protected
EntityManagerInterface
$em
Methods
resolveRelations()
protected
resolveRelations(object $entity) : void
Parameters
- $entity : object
bridgeScalarFkToAssociation()
Fills a ManyToOne association from the value of the scalar foreign key that shares the same join column (typically `$menuId` and `menu`, `$pageId` and `page`). Does nothing when the association is not mapped in this entity variant or the scalar is missing or empty (null/0).
private
bridgeScalarFkToAssociation(object $entity, string $associationName) : void
Parameters
- $entity : object
- $associationName : string
linkOwnedCollections()
Links the owning side of owned collections (cascade persist OneToMany, for example translations): sets the back-reference to the parent (`mappedBy`) on every child so that Doctrine writes the FK on flush. Without it newly hydrated children would be saved with a null foreign key (or the insert would fail).
private
linkOwnedCollections(object $entity) : void
For children whose identifier is itself a foreign key to the parent (typically
translations: PK = page_id + language_id, where page_id is also the FK), the scalar
identifier is filled from the parent id. Doctrine does not derive it from the association
(it is not a derived identity through #[Id] on the association), so it would fail with
EntityMissingAssignedId. Works for an existing parent (the id is known); a brand-new
parent (the id appears only on flush) needs a two-phase write.
Parameters
- $entity : object
resolveFkIdentifierField()
Finds the name of the identifier field of the target entity whose database column equals the join column of the back association (`mappedBy`), that is an identifier which is also a foreign key to the parent. Returns null when there is none.
private
resolveFkIdentifierField(class-string $targetEntity, string $mappedBy) : string|null
Parameters
- $targetEntity : class-string
- $mappedBy : string