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

Schema: support validation/referential integrity for objectid types #25

Closed
inactivist opened this issue Mar 20, 2013 · 5 comments
Closed

Comments

@inactivist
Copy link

"Would be helpful" if the schema supported referential integrity validation for objectid types during POST/PATCH ops.

For example, in eve-demo:

works = {
    'schema': {
        # snip
        'owner': {
            'type': 'objectid',
            'required': True,
        },
    }

There is no (simple) way to ensure that the works.owner value exists in the people collection. Currently, one must implement a custom Validator class in order to enforce basic RI rules.

A simplistic approach would allow schema-based specification of the referenced collection name, and if the value doesn't exist, raise an exception.

A more flexible approach would allow optional specification of a callable validation method, thus providing more sophisticated business rules. A default behavior would be to verify existence in the referenced collection per the 'simplistic' approach.

@inactivist
Copy link
Author

This raises a related feature: Support for a list of objectid types validated against some collection (all objectid items in the list must exist in some collection.

Should this require writing a custom Validator? (Using a custom Validator may be the correct solution, but I don't know enough to decide.)

This case could be handled in the application using a callable validation function if that capability exists.

@nicolaiarocci
Copy link
Member

Thanks, this is needed indeed. I'm going work on it in a few days, as soon as I'm done with the first documentation draft.

@cudevmaxwell
Copy link
Contributor

Working on this now.

@nicolaiarocci
Copy link
Member

How about somethig like this:

'owner': {
            'type': 'objectid',
            'required': True,
            'data_relation': {
                'resource': 'people',
                'field': '_id'
            }
        },

At the cost of a little complexity The data_relation keyword would allow to specify both the parent collection and the linked field, allowing for some flexibility (you can reference non-primary key fields).

@inactivist
Copy link
Author

That looks like a simple and workable solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants