Relationship Loading Strategies
SQL only feature
Controls how relationships get loaded when querying. By default, populated relationships
are loaded via the select-in
strategy. This strategy issues one additional SELECT
statement per relation being loaded.
The loading strategy can be specified both at mapping time and when loading entities.
For example, given the following entities:
The following will issue two SQL statements. One to load the author and another to load all the books belonging to that author:
If we update the Author.books
mapping to the following:
The following will issue one SQL statement:
You can also specify the load strategy as needed. This will override whatever strategy is declared in the mapping. This also works for nested populates:
#
Changing the loading strategy globallyYou can use loadStrategy
option in the ORM config:
This value will be used as the default, specifying the loading strategy on
property level has precedence, as well as specifying it in the FindOptions
.