Closed igorbenav closed 1 month ago
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 100.00%. Comparing base (
03d4a2d
) to head (8191543
).
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
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).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: