-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Cannot get the Identifier of the record #9516
Comments
you can call {
type: '@identity',
name: 'identifier',
kind: 'derived',
options: { key: '^' },
}, This presumes you've registered the derivations made available by the schema-record package for use with defaults / identity etc. import { registerDerivations } from '@warp-drive/schema-record/schema';
//...
registerDerivations(schema); |
Sorry for the delay. I added the field to my schema and called the I had some trouble with getting it to work because there is also a |
Awesome! |
After reading the source code a bit I was getting bold and also moved my {
type: '@identity',
name: 'id',
kind: 'derived',
options: { key: 'id' },
} As it turns out you can add several |
@Jopie01 this is actually one of the things provided by see: data/packages/schema-record/src/schema.ts Lines 33 to 67 in f30fdf4
specifically, primaryKey is set by the special |
Hmm, I tried to remove the I now start with setting up a new schema with the fields. Then I walk through my list of fields which I got from the backend and push them also to the fields list. let newSchema = {
type: <model>,
legacy: true,
traits: [],
fields: [{
type: null,
name: 'isDestroyed',
kind: 'attribute',
options: {},
}, {
type: null,
name: 'isDestroying',
kind: 'attribute',
options: {},
}, {
type: '@identity',
name: 'id',
kind: 'derived',
options: { key: 'id' },
}, {
type: '@identity',
name: 'identifier',
kind: 'derived',
options: { key: '^' },
}]
}
/*
.... walk through my list of fields and add them to the schema
*/
this.registerResource(newSchema);
registerDerivations(this); |
ah, you're using legacy mode. Try the |
That's correct, I have to wait until PR #9320 lands or ready to test. I suspect there won't be a very big difference between legacy and the new approach? |
yeah, you only need legacy mode when using hasMany/belongsTo/attribute. didn't see any hasMany/belongsTo in what you posted above though 😅 legacy also has a data/packages/model/src/migration-support.ts Line 144 in eb9e8a9
|
I added a comment which stated "walk through my list of fields and add them to the schema" .... 😛 and in that list of fields there are
I will keep it as is for now. It works perfectly well and I have to clean up my customization of the schema class some day nonetheless. At that moment I will look into the |
I'm using the most recent alpha versions of Ember-Data / WarpDrive. I migrated everything to the newest Schema service and SchemaRecord. However the fields and relationships are the Legacy ones. Everything works nicely, data is fetched and displayed correctly.
Now I want to get the
Identifier
from the record, but I can't. I always get the errorUncaught Error: No field named identifier on ui.menu
. Logging the record to the console, I see that everything is there. I get a Proxy with a Symbol(Identifier) which contains the needed data. I can get the identifier by calling thetoString
function which return everything as a string. But that's not what I want.I'm surely missing something, but what? I just want the identifier of that record.
The text was updated successfully, but these errors were encountered: