Data relationships
Table of contents
Data relationships define how different data models connect and interact with each other. Real-world applications rely on relational connections—such as:
- A User writes many Posts.
- A Post has many Comments written by different Users.
- An Order contains multiple line-item Products.
Doypp provides an intuitive visual way to map these connections and automatically handles both direct and indirect relational links across your app.
Direct relationships
A direct relationship connects two data models. Depending on your perspective, the relationship is expressed in one of two complementary ways:
- Has: The parent model has child models (e.g., a
Userhas manyPosts). - Belongs to: The child model belongs to a parent model (e.g., a
Postbelongs to aUser).
Example 1: Author and Posts
In a forum application, a user authors multiple posts:
Example 2: Posts and Comments
Expanding the forum structure, users can create posts and leave comments on those posts:
Automatic Bidirectional Synchronization
Relationships in Doypp are bidirectional. You only need to define the relationship from one side, and Doypp automatically creates and maintains the inverse relationship in the database.
For example, if you configure User has many Posts on the User model, the system automatically configures Post belongs to User on the Post model. You never have to manually create reciprocal foreign keys or cross-reference tables.
Indirect relationships
When you define direct relationships between models, Doypp analyzes the relationship graph and establishes indirect relationships automatically.
Indirect relationships are one of Doypp’s most powerful capabilities, allowing you to display and filter multi-hop relational data across screens without writing SQL joins or custom backend code.
Example 3: Comments on a User’s Posts
- Direct relationships defined by you:
Userhas manyPosts, andPosthas manyComments. - Indirect relationship derived by Doypp:
Userreceives comments on their posts.
Example 4: Commenters on a Post
- Direct relationships defined by you:
Posthas manyComments, and eachCommentbelongs to aUser. - Indirect relationship derived by Doypp: A
Posthas multiple commenters.
Step-by-Step: Adding Relationships
Here is how to set up relationships in the visual editor for a forum application where users write posts and comments:
- Create the data models: Add the
PostandCommentmodels in the Data Model editor. - Review your model list: Confirm all required models appear on your dashboard.
- Establish the relationship: Open the relationship configuration and link the models (e.g., set
Postto has manyComments). - Inspect the relational graph: Verify the updated relationship graph. The inverse links are created automatically.
Related Topics
- Define entity fields and types in Data Fields.
- Explore join models and historical HABTM patterns in Many-to-Many Relationships.
- Display related records using embedded lists in Page Elements: Child Views.