Version: 4.1
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
You can also populate all relationships by passing
populate: true
.
For SQL drivers with pivot tables this means:
For mongo driver its even simpler as no pivot tables are involved:
#
Populating already loaded entitiesTo populate existing entities, you can use em.populate()
.