M
M
Mikhail Shatilov2019-04-17 03:00:54
symfony
Mikhail Shatilov, 2019-04-17 03:00:54

How to make nested entities in Symfony in Doctrine?

The project needs to use the rest api for which the repositories are adapted to be used with the "DataRepository" (doctrine skeleton mapper).
An example of methods in the repository:

public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): iterable
{
    return $this->basicObjectRepository->findBy($criteria, $orderBy, $limit, $offset);
}

public function hydrate($object, array $data): void
{
    $this->basicObjectRepository->hydrate($object, $data);
}

There was a task to add support for nested entities, literally so that findBy would return [Entity1[SubEntity1, Subentity2], Entity2[...]. By solving "on the forehead", you can create an entity in the hydrate method, but I'm sure that it would be wrong to create something in the entity. There seems to be something similar in Doctrine mongodb when working with documents.
How to do?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
OnYourLips, 2019-04-17
@OnYourLips

Add your method to the repository and use the joins in QueryBuilder in it.
By default, proxies are lazy loaded.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question