Many-to-Many Relationships
Table of contents
In relational data modeling, relationships can be One-to-Many or Many-to-Many (often abbreviated as HABTM—”Has and Belongs to Many”). This guide walks through each pattern and explains how Doypp handles join models automatically.
One-to-Many (“Has”)
A One-to-Many relationship occurs when a single parent record connects to multiple child records.
For example, a User writes multiple Posts. When configuring this on the User model, select “has many Posts”:
From the perspective of the Post model, Doypp automatically creates the inverse “belongs to User” relationship.
Many-to-One (“Belongs to”)
The inverse of “Has Many” is “Belongs To”. Each child record references exactly one parent record.
Example: Each post is authored by exactly one user. If you start from the Post model, you can choose “belongs to User”:
Regardless of which side you start from, Doypp establishes both directions symmetrically.
Many-to-Many (“Has and Belongs to”)
A Many-to-Many relationship is required when multiple records on one side can associate with multiple records on the other.
Example: Users can rate posts. A user can rate multiple different posts, and a single post can receive ratings from multiple different users:
When you create a many-to-many relationship between User and Post, Doypp automatically generates an intermediate join model (initially named User_Post):
Understanding Join Models
A join model is not just a behind-the-scenes database connector—it is a full-fledged data model. You can:
- Rename it: Rename
User_Postto a descriptive name likeRate,Bookmark, orEnrollment. - Add custom fields: Store attributes specific to the interaction itself, such as a
score(e.g., 1–5 stars), areviewnote, or atimestamp.
Alternative Setup Approaches
Because Doypp’s relationship engine is modular, you can build this structure using whichever workflow feels most intuitive:
- Automated Many-to-Many: Use the relationship editor to select “Many-to-Many”, letting Doypp generate the intermediate model automatically.
- Manual Join Model via “Belongs To”:
- Create a model named
Rate. - Add a
belongs-to Userrelationship. - Add a
belongs-to Postrelationship.
- Create a model named
- Manual Join Model via “Has Many”:
- Create a model named
Rate. - On
User, add ahas-many Raterelationship. - On
Post, add ahas-many Raterelationship.
- Create a model named
All three approaches produce the exact same relational architecture in the underlying database and visual diagram.
Related Topics
- Review direct and indirect relationships in Data Relationships.
- Display linked parent and child data using Page Elements: Child Views.