Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strong relations with referential integrity #2331

Open
bajtos opened this issue Feb 4, 2019 · 4 comments
Open

Strong relations with referential integrity #2331

bajtos opened this issue Feb 4, 2019 · 4 comments
Labels
epic Relations Model relations (has many, etc.)

Comments

@bajtos
Copy link
Member

bajtos commented Feb 4, 2019

Essentially, we see two levels of relations:

  • Weak relations, where the developer primarily wants to navigate related models (think of GraphQL) and referential integrity is either not important or already enforced by the (SQL) database.
  • Strong relations, where the referential integrity is guaranteed by the framework together with the database.

IMO, referential integrity must be guaranteed at repository level (or lower). For example, when a test helper invokes repository APIs to seed the database with sample data, then we want the referential integrity to be preserved. If we implemented referential integrity at controller level, then consumers of Repository API would be bypassing these checks and would be able to created corrupted data.

Implementation wise, it's important to implement referential integrity in way that does not create any race conditions. For example, a naive implementation calling findById on the source model before creating a new instance of the target model creates a race condition - if another request deletes the source model instance after findById received database response but before create command is set, then we end up with corrupted data.

With SQL databases, referential integrity is typically implemented by defining FOREIGN KEY constraints. In the context of LB4, this means that lb4 migrate must create such constraints based on the relations configured by the app.

With NoSQL databases, users should use different relation types than hasMany, for example referencesMany or embedsMany.

@bajtos bajtos added the epic label Feb 4, 2019
@bajtos bajtos added the Relations Model relations (has many, etc.) label Feb 4, 2019
@dhmlau dhmlau mentioned this issue Apr 5, 2019
22 tasks
@bajtos bajtos added the 2019Q3 label Apr 9, 2019
@dhmlau dhmlau added 2019Q4 and removed 2019Q3 labels Jun 25, 2019
@dhmlau dhmlau added 2020Q1 and removed 2019Q4 labels Sep 10, 2019
@dhmlau dhmlau removed the 2020Q1 label Nov 14, 2019
@odykyi

This comment has been minimized.

@achrinza
Copy link
Member

achrinza commented Mar 19, 2020

Just to quote from the other issue:

Unfortunately this isn’t universal across other connectors as LoopBack doesn’t provide a common interface. For example, the MSSQL connector doesn’t support this natively.

This may be a good opportunity to revisit this soon as it’ll help streamline the use of LoopBack 4 and promote an increase in overall efficiency of the SQL queries.

@stale
Copy link

stale bot commented Dec 25, 2020

This issue has been marked stale because it has not seen activity within six months. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository. This issue will be closed within 30 days of being stale.

@stale stale bot added the stale label Dec 25, 2020
@agnes512 agnes512 removed the stale label Jan 18, 2021
@stale
Copy link

stale bot commented Jul 17, 2021

This issue has been marked stale because it has not seen activity within six months. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository. This issue will be closed within 30 days of being stale.

@stale stale bot added the stale label Jul 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
epic Relations Model relations (has many, etc.)
Projects
Status: Icebox
Development

No branches or pull requests

5 participants