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

Allow _id as a primary key #824

Merged
merged 7 commits into from
Sep 30, 2018
Merged

Allow _id as a primary key #824

merged 7 commits into from
Sep 30, 2018

Conversation

will118
Copy link
Contributor

@will118 will118 commented Sep 26, 2018

I have implemented #681

If there is an edge case or some behaviour not covered by my tests, let me know and I will add the test.

Apologies for the delay. I am committed to getting this merged so feedback is welcome.

Tests

RxCollection

  • Inserting a document with _id set on a schema with _id: primary
  • Inserting a document with _id set on a schema with somethingElse: primary
  • Inserting a document with _id set on a schema with no primary defined (implicit _id)

RxSchema

  • Creating a schema with _id as primary
  • Creating a schema with _id not as primary

@pubkey
Copy link
Owner

pubkey commented Sep 26, 2018

Looks good.
One edge-case: What happens if an primary-field e.g. passportId is set, and I insert an object which contains _id and passportId? I think we should throw an error if this happens.

@will118
Copy link
Contributor Author

will118 commented Sep 27, 2018

@pubkey Great!

Does this logic not cover it:
https://github.com/pubkey/rxdb/pull/824/files#diff-ee35040c15aa81d65903334acff165c9R371

and this test:
https://github.com/pubkey/rxdb/pull/824/files#diff-162336d85de73bd515f48480759e07cdR375

I just tried writing a test for RxCollection where the schema has passportId (primary: true) and _id but of course this is rejected by SchemaCheck!

So I don't think it's possible to write any other tests for this case, let me know if you have any ideas.

@pubkey pubkey merged commit 62832b1 into pubkey:master Sep 30, 2018
pubkey added a commit that referenced this pull request Sep 30, 2018
@pubkey
Copy link
Owner

pubkey commented Sep 30, 2018

Yes you are right. I merged this. Thank you for the great work.

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

Successfully merging this pull request may close these issues.

2 participants