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.
One-to-many support in joins
This fixes #91. Btw I'm not completely satisfied with the implementation, but it's enough for now.
Documentation
Handling One-to-One and One-to-Many Joins in FastCRUD
FastCRUD provides flexibility in handling one-to-one and one-to-many relationships through
get_joined
andget_multi_joined
methods, along with the ability to specify how joined data should be structured using both therelationship_type
(defaultone-to-one
) and thenest_joins
(defaultFalse
) parameters.One-to-One Relationships
get_joined
: Fetch a single record and its directly associated record (e.g., a user and their profile).get_multi_joined
(withnest_joins=False
): Retrieve multiple records, each linked to a single related record from another table (e.g., users and their profiles).Example
Let's define two tables:
Fetch a user and their tier:
The result will be:
One-to-One Relationship with Nested Joins
To get the joined data in a nested dictionary:
The result will be:
One-to-Many Relationships
get_joined
(withnest_joins=True
): Retrieve a single record with all its related records nested within it (e.g., a user and all their blog posts).get_multi_joined
(withnest_joins=True
): Fetch multiple primary records, each with their related records nested (e.g., multiple users and all their blog posts).Warning
When using
nest_joins=True
, the performance will always be a bit worse than when usingnest_joins=False
. For cases where more performance is necessary, consider usingnest_joins=False
and remodeling your database.Example
To demonstrate a one-to-many relationship, let's assume
User
andPost
tables:Fetch a user and all their posts:
The result will be: