Skip to content
Advertisement

Data eager loading in doctrine mongodb

Sorry for my english. I seem to be missing something in the work of doctrine with mongo. I have

JavaScript

And several classes of descendants, like:

JavaScript

And a resource class with a reference to attributes

JavaScript

The resource is created normally, but when fetching by id, the attributes field is not loaded until I try to access the property directly, i.e .:

JavaScript

twig dump

$resource->getAttributes()->getCreated() – will return creation date and all fields.

I have a two questions:

  1. How to make the doctrine automatically load all the data?
  2. How do I specify a repository for an abstract class in my example?

Thanks for the help.

Advertisement

Answer

The closest thing to fetch="EAGER" in ODM is a process called “priming references”. Contrary to ORM’s EAGER this will make two database queries (one for your casual documents you’re looking for and another one for their primed references) as there is no feasible way to achieve JOIN-like fetching. You can read more about priming in the docs: https://www.doctrine-project.org/projects/doctrine-mongodb-odm/en/2.2/reference/priming-references.html

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement