Data relationships

Table of contents

  1. Direct relationships
    1. Example 1: Author and Posts
    2. Example 2: Posts and Comments
    3. Automatic Bidirectional Synchronization
  2. Indirect relationships
    1. Example 3: Comments on a User’s Posts
    2. Example 4: Commenters on a Post
  3. Step-by-Step: Adding Relationships
    1. Related Topics

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 User has many Posts).
  • Belongs to: The child model belongs to a parent model (e.g., a Post belongs to a User).
graph LR; P(Parent Model) --> |has| C(Child Model);
graph RL; C(Child Model) --> |belongs to| P(Parent Model);

Example 1: Author and Posts

In a forum application, a user authors multiple posts:

graph LR; User -- has many --> Post;
graph RL; Post -- belongs to --> User;

Example 2: Posts and Comments

Expanding the forum structure, users can create posts and leave comments on those posts:

graph LR; User -- has many --> Post; Post -- has many --> Comment; User -- has many --> Comment;
graph RL; Post -- belongs to --> User; Comment -- belongs to --> Post; Comment -- belongs to --> User;

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: User has many Posts, and Post has many Comments.
  • Indirect relationship derived by Doypp: User receives comments on their posts.
graph LR; User -- has many --> Post; Post -- has many --> Comment; User -. "has/receives comments on posts" .-> Comment;

Example 4: Commenters on a Post

  • Direct relationships defined by you: Post has many Comments, and each Comment belongs to a User.
  • Indirect relationship derived by Doypp: A Post has multiple commenters.
graph LR; Post -- has many --> Comment; Comment -- belongs to --> User; Post -. "has many (Commenters)" .-> User;

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:

  1. Create the data models: Add the Post and Comment models in the Data Model editor.
  2. Review your model list: Confirm all required models appear on your dashboard.
  3. Establish the relationship: Open the relationship configuration and link the models (e.g., set Post to has many Comments).
  4. Inspect the relational graph: Verify the updated relationship graph. The inverse links are created automatically.
Add new data model
Step 1: Add new data models
Post and Comment models added
Step 2: Confirm models in the overview
Configure Post has Comments relationship
Step 3: Define the relationship between Post and Comment
Data relationships visual diagram
Step 4: Verified bidirectional relationships in the visual diagram