Closed coeit closed 2 years ago
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).
For now we only support foreignkey arrays for many_to_many
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 amany_to_one
/one_to_many
relation via a foreignkey array stored on theone_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 theone_to_many
) we can look at the association type and where the targetkey is stored (see above). Both will haveimplementation: "foreignkeys"
.Spec
Pending