In the rare case of a parent-child relationship inside the same model, i.e. a graph structure of the data, a node can have a to-one association to a "parent" and a to-many association to "descendants". Our update API (resolver) accepts arguments for both ends of the relationship (association).
To explain the problem consider this example. As shown, the problem arises if the "parent" shall be set to any node, while the "descendants" include the node to be updated itself. Thus the foreign key "parent_id" of the current record shall be set to two different conflicting values: The node's own ID and at the same time the other "parent" as provided in the input.
Solution
In the case of two associations that
are with the same target data model as the source data model (parent-child relation),
both ends of the association, to-ne and to-many, are declared,
both associations use the same foreign-key (just to check and be really sure)
the code-generator should create an additional validation filter for the update, and also create, arguments. The validation filter should throw a validation error, if and only if
the record's own id appears in the "add_descendants" argument, and
at the same time the "add_parent" argument is provided and set to something different that the record itself.
Question: Can this be also a problem in the "remove-association" case?
Think through a similar case providing "remove_parent" and "remove_descendants" arguments. Can a similar problem arise?
Question: Can the above problem occur in 'create' cases?
Yes, if the following conditions are met:
We use "internal IDs", i.e. a unique attribute for which the user provides values - so non-database sequences. This enables the user of Zendro to provide the record ID before creation happens, thus the record can be associated with itself.
If check-existence is switched of, so the record does not need to be persistent to be able to be associated with itself.
Conclusion
We need the above validation check also for create cases. At least those that have the above conditions.
In the rare case of a parent-child relationship inside the same model, i.e. a graph structure of the data, a node can have a to-one association to a "parent" and a to-many association to "descendants". Our update API (resolver) accepts arguments for both ends of the relationship (association).
To explain the problem consider this example. As shown, the problem arises if the "parent" shall be set to any node, while the "descendants" include the node to be updated itself. Thus the foreign key "parent_id" of the current record shall be set to two different conflicting values: The node's own ID and at the same time the other "parent" as provided in the input.
Solution
In the case of two associations that
the code-generator should create an additional validation filter for the update, and also create, arguments. The validation filter should throw a validation error, if and only if
Question: Can this be also a problem in the "remove-association" case?
Think through a similar case providing "remove_parent" and "remove_descendants" arguments. Can a similar problem arise?