Include Class
The Include class facilitates eager loading for models with relationships. Below is a table detailing the parameters available for the Include class
The following example demonstrates how we can use the Include class do to eager loading by fetching the profile of the user when we fetch the user by primary key.
user_with_profile = mysql_loom.find_by_pk(
instance=User,
pk=userId,
select=["id", "username"],
include=[Include(model=Profile, select=["id", "avatar"], has="one")],
)
Argument |
Description |
Type |
Default |
Required |
|
The model to be included when eagerly fetching records. |
|
– |
|
|
The |
|
|
|
|
The list of order specifications for sorting the included data. |
list[ |
|
|
|
The maximum number of records to include. |
|
|
|
|
The number of records to skip before including. |
|
|
|
|
The list of columns to include. |
|
|
|
|
The relationship type between the current model and the included model. |
|
|
|
|
The extra included models. |
list[ |
|
|
|
The alias name for the included model. Very important when mapping self relations. |
|
|
|
Note
You can include a single or multiple relations when doing eager data fetching in dataloom.