Skip to content
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

Implement a validation filter for contradictory association update arguments #137

Open
asishallab opened this issue Jul 23, 2020 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@asishallab
Copy link
Member

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

  1. are with the same target data model as the source data model (parent-child relation),
  2. both ends of the association, to-ne and to-many, are declared,
  3. 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

  1. the record's own id appears in the "add_descendants" argument, and
  2. 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?

@asishallab asishallab added the bug Something isn't working label Jul 23, 2020
@asishallab
Copy link
Member Author

Question: Can the above problem occur in 'create' cases?

Yes, if the following conditions are met:

  1. 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.
  2. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants