Enforce integrity constraints for module links #11405
cortopy
started this conversation in
Feature Requests
Replies: 2 comments
-
Hey @cortopy, appreciate the feedback. These are all great feature requests–some were already on our radar. We expect to look into adding these soon. |
Beta Was this translation helpful? Give feedback.
0 replies
-
thanks so much @olivermrbl ! Hearing that it's on your radar makes me very happy. I'd assume that there would more than one way to achieve this and a solution design would be required. I'd be very glad to contribute to either ideation or some kind of PR |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
According to the docs:
If a one-to-many relation is desired, then the
isList
option can be declared to represent that in the schema.However, that option doesn't do anything apart from changing the way in which typescript types are generated. There are many unexpected behaviours.
Unexpected behaviours
Creation of links doesn't guarantee data consistency
Even if
isList: false
is specified (default), doing the following will create two links:This really caught me out, as I thought that there would some kind of integrity constraints in postgres that would stop applications from creating more than one link if a relationship is one-to-one. The database is a RDBS after all, and this is totally unexpected.
Typescript types are not safe
Because
isList
is false, type are only generated "as if" the response from the query is guaranteed to never be an array, but this isn't true, since a query will return an array if there's more than one.Query doesn't work as expected
According to the docs on query,
But it seems that me that this is cosmetic and doesn't really represent any schema constraints. If there is more than one link as per the example above, querying using the singular would still return an array.
Feature request
I would have thought that following applies:
link.create
throws an error if the link already exists or if either entity is already linked to a different record.Beta Was this translation helpful? Give feedback.
All reactions