ScaffoldHub - v2
  • Introduction
  • Modeling
    • Two-way Relationships
  • Setup
    • Backend
    • Frontend
    • File Storage
    • Emails with SendGrid
    • Payments with Stripe
  • Debugging
  • Deployment
    • Database
      • SQL
      • MongoDB
    • Backend
      • Google Cloud - App Engine
      • Google Cloud - Run
      • Under construction...
    • Frontend
      • Firebase Hosting
      • Heroku w/ Subdomains
      • Under construction...
  • Features
    • Projects
    • Preview
    • Tenants
      • Single-Tenant
      • Multi-Tenant
      • Multi-Tenant (w/ subdomains)
    • Payments
    • Security
    • Authentication
      • Sign-in and Sign-up
      • Invitation
      • Password Reset
      • Password Change
      • Email Verification
    • Audit Logs
    • Settings
    • Internationalization (I18n)
    • Entity
      • Form
      • Filter and List
      • Export
      • Import
    • API Documentation
  • Architecture
    • Security
    • File Storage
    • Internationalization (I18n)
    • Payments
    • Typescript Support
    • Rate limiting
    • Technologies Versions
    • Under construction...
  • Recipes
    • Testing the API with Postman
    • Enterprise sign-in with WorkOS
    • Under construction...
  • Support
  • Changelog
    • Documentation
    • Scaffolds
  • Custom Development
  • Legacy Scaffolds
  • Go to ScaffoldHub
Powered by GitBook
On this page

Was this helpful?

  1. Modeling

Two-way Relationships

PreviousModelingNextSetup

Last updated 4 years ago

Was this helpful?

Two-way relationships are something that is not so intuitive, so let me explain here in detail.

As an example, we will have this setup:

Product

  • Name

  • Category (Relation to One)

  • Unit Price

  • Photos

Category

  • Name

  • Products (Relation to Many)

Product.Category is a two-way relationship to Category.Products, because when you change a Product.Category, it changes the Category.Products.

Demonstration

On products, we have Speaker and Headphone that belongs to the category Electronics.

In this case, the category form would look like this:

Now let's suppose we remove Speaker from the Electronics category.

If we go back to products, we see that only Headphone is related to the Electronics category, because changing the products field, also impacted on the Product.Category records.

Product.Category
Category.Products