Skip to main content

Module relation_many_to_many

Module relation_many_to_many 

Source
Expand description

Many-to-many relations use a join model with a has_many relation on each endpoint and a has_many(via = ...) relation for direct traversal.

Functionsยง

composite_join_key_prevents_duplicate_links
A composite primary key on the join model prevents duplicate links while allowing each endpoint to participate in other links.
filter_through_join_model
Parent queries can use .any() on the join relation. The predicate can traverse to the opposite endpoint and can also inspect fields stored on the join model.
filter_through_via_from_both_sides
Parent queries can apply .any() directly to either derived relation, without spelling the join model in the predicate.
include_from_both_sides
Preloading works in both directions and keeps results grouped under the correct endpoint, including endpoints with no join rows.
mutate_link_through_join_model
Links are created, updated, and removed by mutating the join model. This preserves relation data such as role and leaves both endpoint records intact when the link is removed.
query_from_both_sides
Both endpoints can traverse the same join rows. The derived query retains normal query operations such as ordering and returns an empty list when no join rows exist.
self_referential_followers_and_following
A self-referential many-to-many relation uses pair hints to distinguish the two foreign keys on the join model. Each direction then exposes its own has_many(via = ...) traversal.