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

Feature request: Optional ref properties #2285

Closed
DDoerner opened this issue Jun 16, 2020 · 3 comments
Closed

Feature request: Optional ref properties #2285

DDoerner opened this issue Jun 16, 2020 · 3 comments

Comments

@DDoerner
Copy link
Contributor

Case

Feature Request

Issue

We have a server-side data model with an optional foreign key. This property can either be a string referencing another collection or NULL. It is not possible to define this schema for rxdb.

Example

Let's say we have two classes, User and Car. Some users have cars, others don't. So the property user.car_id can either point to a car or be null.

A possible schema for User:

  {
    version: 0,
    type: 'object',
    title: 'user',
    required: [ 'id', 'name' ],
    properties: {
      id: {
        type: 'string',
        primary: true
      },
      car_id: {
        type: 'string',
        ref: 'car'
      },
      name: {
        type: 'string'
      }
    }
  }

This schema will fail (e.g. during a migration) for any entry in the database with a car_id of NULL, since the schema does not allow for null values. It does not matter whether 'car_id' is a required property or not.

Possible resolutions

We hope for either:

  • ref-Properties allow for a type of ['string', 'null']
  • ref-Properties allow for NULL-values if the property is not required
@pubkey
Copy link
Owner

pubkey commented Jun 16, 2020

I think this is a bug. The 2nd proposal should be working.

@DDoerner
Copy link
Contributor Author

I've looked into it and the validate plugin throws the error. RxDB itself might allow ref properties with value NULL, but is-my-json-valid does not, since the type does not specify NULL as well. And I assume that the other validate plugins act the same (although I haven't tested it yet), since that is the correct behavior accrording to JSONSchema.

So the only solution I see is the 1st proposal. Or is there anything that can be said against that change?

@pubkey
Copy link
Owner

pubkey commented Jun 18, 2020

Closing this, PR is merged. Thank you.

@pubkey pubkey closed this as completed Jun 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants