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

Indexes do not work in objects named "properties" #697

Closed
grantcodes opened this issue Jun 23, 2018 · 5 comments
Closed

Indexes do not work in objects named "properties" #697

grantcodes opened this issue Jun 23, 2018 · 5 comments
Labels

Comments

@grantcodes
Copy link

Case

Bug

Issue

Indexes do not work in objects named "properties"

Info

  • Environment: Node.js
  • Adapter: IndexedDB

Code

  const collection = await myDatabase.collection(
    name: "posts",
   schema: {
      version: 0,
      id: 'post',
      type: 'object',
        properties: {
          type: 'object',
          properties: {
            name: {
              type: 'string',
              index: true,
            },
          },
        },
      },
  );

I am storing microformats2 json which defines a property named "properties", if you set an index inside that property RxDB will throw an error with the schema, even though it is totally valid

"SchemaCheck: given index is not defined in schema" is the thrown error.

It definitely is caused by replacements going on here:

const schemaObj = objectPath.get(jsonID, 'properties.' + key.replace(/\./g, '.properties.'));

I am not sure what would be required to fix it, you would likely need to check for the nesting of properties.properties somehow.

@pubkey
Copy link
Owner

pubkey commented Jun 23, 2018

You have nested properties directly into properties. I do not think this is valid json-schema. How would an object look that matches your schema?

EDIT: aah, now I know what you meant to do. But what does the second type do?

@grantcodes
Copy link
Author

I'm not sure what you mean by "the second type"

But the data would look something like this:

{
  type: ['h-entry'],
  properties: {
    name: ['Title']
    content: ['Post content']
  }
}

I simplified the schema to try and just show the part relevant to the bug. But in reality it is much more complex

@pubkey
Copy link
Owner

pubkey commented Jun 24, 2018

Ok this is definitely a bug. A PR would be welcomed.

@pubkey pubkey closed this as completed in f94bc53 Jun 25, 2018
@pubkey
Copy link
Owner

pubkey commented Jun 25, 2018

@grantcodes thx for pointing this out. I fixed it in the referenced commit.

@grantcodes
Copy link
Author

Awesome! Thanks for the quick fix @pubkey

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

No branches or pull requests

2 participants