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

hasManyThrough: should not create through model for non-existent source and targets #5996

Closed
hacksparrow opened this issue Jul 23, 2020 · 2 comments
Labels
bug Repository Issues related to @loopback/repository package

Comments

@hacksparrow
Copy link
Contributor

This appointment is getting created despite the source and target model ids not existing.

{
  "date": "2020-07-23T13:29:09.924Z",
  "doctorId": 90000000,
  "patientId": 20000000000000
}
@achrinza achrinza added the Repository Issues related to @loopback/repository package label Jul 23, 2020
@agnes512
Copy link
Contributor

@hacksparrow thanks for opening the issue 👍 I think this is because of the design. I remember @Janny had the same question before, and we discussed it in #5719 (review) (quote from @bajtos ):

So far, LoopBack implements what we call "weak relations", where it's up to the database to enforce any referential integrity. Typically, when using SQL, there is a foreign key constraint configured to ensure the "link" rows cannot point to a source/target model that does not exist, and also that it's not possible to delete a source or a target row before all their "link" rows are removed first. (It's also possible to configure cascading delete, but let's not get distracted.) We have been discussing "strong relations" in the past, but they weren't a priority so far. You can learn more in #2331.

IMO, we should keep the current ("weak") design, if only for consistency with other existing relational APIs, and mention in the documentation that the referential integrity must be configured at database level.

WDYT?

@hacksparrow
Copy link
Contributor Author

Got it. The notice on top of the doc should suffice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Repository Issues related to @loopback/repository package
Projects
None yet
Development

No branches or pull requests

3 participants