Zendro-dev / graphql-server-model-codegen

Command line utility to auto-generate the structure files for a graphql server
MIT License
1 stars 2 forks source link

implement foreignkey arrays for one_to_many relations #185

Closed coeit closed 2 years ago

coeit commented 3 years ago

Summary

Currently foreignkey arrays are supported when using a many_to_many relation. Even though it might be weird e.g. for relational databases we can also implement a many_to_one / one_to_many relation via a foreignkey array stored on the one_to_many side of the association.

Implementation

Instead of updating both sides of the association (both fK arrays) we only need to update the model that holds the array, similiar to how in the standard case (one foreign key) we update only the model that holds the foreignkey. We do this by calling the function to update the array in the model that holds the foreign-key.

For details look at the implementation of updating foreignkeys for the different storage types.

data-model-definition

To differentiate between the standard (one foreignkey on the many_to_one end) way of associating records and the foreignkey array (stored on the one_to_many) we can look at the association type and where the targetkey is stored (see above). Both will have implementation: "foreignkeys".

Spec

Pending

coeit commented 3 years ago

Problem:

There is no way to know whether it really is a to_one from the side, that doesn't hold the array. Therefore the above approach can In theory can be used for many-to-many with high likelihood of inefficiency (must search whole other data model to find associated <- also a disadvantage with classic RDB one-to-many via foreign keys, which is why in that case indices are highly recommended).

Conclusion

For now we only support foreignkey arrays for many_to_many