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

Disambiguate the meaning of _id #72

Closed
louischan-oursky opened this issue Sep 26, 2016 · 2 comments
Closed

Disambiguate the meaning of _id #72

louischan-oursky opened this issue Sep 26, 2016 · 2 comments

Comments

@louischan-oursky
Copy link
Contributor

louischan-oursky commented Sep 26, 2016

When _id is included as a property of the attrs of Record constructor, it is expected to be a typed id, i.e. my_table_name/some-id

After the record instance is constructed, _id is typeless id, i.e. some-id.

It is very confusing. It would be better to support id as one of the property of attrs which is interpreted as typed id. The new constructor must issue deprecation warning for users who still use _id for the constructor. Then _id will always mean typeless id.

const Note = skygear.Record.extend('note');
const noteRecord = new Note({
  _id: 'note/1',
});
console.log(noteRecord._id); // this logs "1"
@cheungpat
Copy link
Contributor

@louischan-oursky

We have this terminology: Record ID (note/42) consists of Record Type (note) and Record Name (42).

The _id field contains record type information because this is how the data is transmitted from the server to the SDK. The data is passed to the constructor you mentioned so to construct a Record. Because of this, in the forseeable future, _id passed to this constructor will have type information because not doing so will break HTTP API compatibility.

In the realm of the JS SDK, I think the recommended approach is to get Record ID information from id property (without _), which returns record type + record name. You are not supposed to use or know about _id. For this reason there is no point in “disambiguating the meaning of _id”.

You are having problem because you are unable to pass a Record into the constructor to create a new object (i.e. the copy constructor you referenced in #73). To solve this problem is easy: if _id does not contain record type information, the constructor should assume that the record type is the same as the record type when calling extend(...).

louischan-oursky added a commit to louischan-oursky/skygear-SDK-JS that referenced this issue Sep 26, 2016
@cheungpat
Copy link
Contributor

This should be handled in #73

rickmak pushed a commit to rickmak/skygear-SDK-JS that referenced this issue Oct 31, 2016
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