-
Notifications
You must be signed in to change notification settings - Fork 1
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
Feature: Automatic handling of to_one conflicting foreign keys #78
Comments
To handle this we can in the resolver (e.g. one_to_one remove associations:sql
neo4j
mongodb
cassandranot possible. need to fetch inside model, i guess... |
Picking up on the above CE discussion: In conclusion, looking at this from a conceptual point of view, the single-end foreign-key implementation of one-to-one associations requires a to a degree inefficient consistency insurance. And correctly did we previously identify a single-end foreign key implementation of a one-to-one association as transition to the paired-end implementations of associations, because this specific case implies the requirement for updating two ends of the associations, even though just a single foreign key is used. There is in non-distributed setup and non-Cassandra storages the option to implement the CE in one less step, i.e. executing an UPDATE statement like the above example in SQL.
This issue shows that the above "extension" of the parrot.remove_person_id does not work in all storages, i.e. distributed setup and Cassandra.
How could we generate the above code using our Zendro tools (templates)? Possible solutions to the CE conundrum:
Two groups: KISS, but inefficient (1), and Efficient, but complex (2-4) Final decision on the CE for single-end FK one-to-one associations (SE O2O):
|
Asis' suggested solution for DDM:
keep consistency in behavior would be ideal. |
Summary
Currently when managing a
x_to_one
association there is no mechanism in place to alert the user of possible ramifications when updating the association.many_to_one
In case of a
many_to_one
this means zendro will just overwrite the foreignKey without warning the user, which could be seen as an intended feature. There will be no "faulty" data writtenone_to_one
Since Zendro handles a one_to_one very much the same to a many_to_one (via a foreignKey in one of the models) currently there is no checks done that a create or update mutation could lead to any unexpected data. The user can counteract this behavior by specifically setting a
unique constraint
on the foreignKey column. Zendro will warn the user on code-generation about this. If ignored this can lead to unexpected "faulty" data where the uniqueness of the association is violated.DDM
In case of a
ddm
it is possible, though probably not very common, to using zendro to distribute data of a single table over multiple databases. In this case aunique constraint
on the database column directly would not be sufficient to ensure theone_to_one
integrity.Solutions
Backend
On code-generation use the
asyncValidatorFunction
to automatically mimic aunique constraint
on foreignKey columns (one_to_one). This would prevent creation/update of records by throwing avalidationError
, independent of storageType. Note that this is a performance-hampering process and should be documented as such.Frontend
The SPA can automatically prevent writing of faulty data by preventing the user to use the functions or automatically correct data (if a new associated record is created from the end that doesn't hold the foreignKey we need to manually remove a possible already existing association).
Notes
Make sure the user is aware of zendro's handling of
one_to_one
association by documenting the above.The text was updated successfully, but these errors were encountered: