Version: 2.7
Smart Nested Populate
MikroORM
is capable of loading large nested structures while maintaining good
performance, querying each database table only once. Imagine you have this nested
structure:
Book
has onePublisher
(M:1), oneAuthor
(M:1) and manyBookTag
s (M:N)Publisher
has manyTest
s (M:N)
When you use nested populate while querying all BookTag
s, this is what happens in
the background:
- Load all
BookTag
s - Load all
Book
s associated with previously loadedBookTag
s - Load all
Publisher
s associated with previously loadedBook
s - Load all
Test
s associated with previously loadedPublisher
s - Load all
Author
s associated with previously loadedBook
s
For SQL drivers with pivot tables this means:
For mongo driver its even simpler as no pivot tables are involved:
#
Using EntityLoader manuallyUnder the hood, EntityManager uses EntityLoader to populate other entities. You can use it manually if you already have list of entities (e.g. queried via QueryBuilder):