Using get_joined
and get_multi_joined
for multiple models
#26
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.Warning
If both single join parameters and
joins_config
are used simultaneously, an error will be raised.