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 should allow primary and ref at the same time #2747

Closed
beorn opened this issue Dec 10, 2020 · 3 comments
Closed

Schema should allow primary and ref at the same time #2747

beorn opened this issue Dec 10, 2020 · 3 comments

Comments

@beorn
Copy link
Contributor

beorn commented Dec 10, 2020

Case

I'd like to have two collections be related through their id - e.g., a collection of nodes with the path for each node in a separate collection:

    nodes: {
      schema: {
        version: 0,
        type: "object",
        properties: {
          id: { type: "string", primary: true },
        },
      },
    },
    paths: {
      schema: {
        version: 0,
        type: "object",
        properties: {
          id: { type: "string", ref: "nodes", primary: true },
        },
      },
    },
  })

Issue

But it seems this is not possible - is there any reason for this?

Uncaught (in promise) RxError (SC5): RxError:
SchemaCheck: fieldname cannot be primary and ref at same time
Given parameters: {
fieldName:"id"}
    at newRxError (http://localhost:3000/server/index.js:71151:10)
    at checkField (http://localhost:3000/server/index.js:64260:73)
    at http://localhost:3000/server/index.js:64301:9
    at Array.forEach (<anonymous>)
    at traverse (http://localhost:3000/server/index.js:64299:29)
    at http://localhost:3000/server/index.js:64306:7
    at Array.forEach (<anonymous>)
    at traverse (http://localhost:3000/server/index.js:64299:29)
    at validateFieldsDeep (http://localhost:3000/server/index.js:64310:3)
    at checkSchema (http://localhost:3000/server/index.js:64358:3)

I would of course be responsible for setting the id when creating items.

Info

  • Environment: Electron 11.0.3 renderer (Chrome M87)
  • Adapter: IndexedDB
  • Stack: Typescript, React, electron-forge
@pubkey
Copy link
Owner

pubkey commented Dec 12, 2020

Yes that makes sense. I have no idea why I included this check.

@pubkey
Copy link
Owner

pubkey commented Dec 22, 2020

Can you make a PR with a test case?

@pubkey
Copy link
Owner

pubkey commented Jan 3, 2021

I solved this in the linked commit.

@pubkey pubkey closed this as completed Jan 3, 2021
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