Using get_joined and get_multi_joined for multiple models
Added
Now get_joined and get_multi_joined can be used with multiple models.
Detailed
To facilitate complex data relationships, get_joined and get_multi_joined can be configured to handle joins with multiple models. This is achieved using the joins_config parameter, where you can specify a list of JoinConfig instances, each representing a distinct join configuration.
Example: Joining User, Tier, and Department Models
Consider a scenario where you want to retrieve users along with their associated tier and department information. Here's how you can achieve this using get_multi_joined.
Start by creating a list of the multiple models to be joined:
In this example, users are joined with the Tier and Department models. The join_on parameter specifies the condition for the join, join_prefix assigns a prefix to columns from the joined models (to avoid naming conflicts), and join_type determines whether it's a left or inner join.
[!WARNING]
If both single join parameters and joins_config are used simultaneously, an error will be raised.
Using
get_joined
andget_multi_joined
for multiple modelsAdded
Detailed
To facilitate complex data relationships,
get_joined
andget_multi_joined
can be configured to handle joins with multiple models. This is achieved using thejoins_config
parameter, where you can specify a list ofJoinConfig
instances, each representing a distinct join configuration.Example: Joining User, Tier, and Department Models
Consider a scenario where you want to retrieve users along with their associated tier and department information. Here's how you can achieve this using
get_multi_joined
.Start by creating a list of the multiple models to be joined:
Then just pass this list to joins_config:
In this example, users are joined with the
Tier
andDepartment
models. Thejoin_on
parameter specifies the condition for the join,join_prefix
assigns a prefix to columns from the joined models (to avoid naming conflicts), andjoin_type
determines whether it's a left or inner join.