Closed jrdn91 closed 6 years ago
the response does not have an id and your record does not either. Is being thrown on the POST response to my server
the response does not have an id and your record does not either.
POST
I have a model for a tag
tag
export default DS.Model.extend({ firstName: DS.attr('string'), lastName: DS.attr('string'), template: DS.attr('number') });
Then I want to save a bunch at once so I created a bunch of these tag records and have a taglist record with a relationship
taglist
export default DS.Model.extend({ modelList: DS.hasMany('tag') });
Which also has a serializer
export default DS.JSONAPISerializer.extend(SaveRelationshipsMixin, { attrs: { modelList: { serialize: true } } });
I create this record like so
const modelList = tags.map((tag) => { return this.store.createRecord('tag', { firstName: tag[firstNameKey], lastName: tag[lastNameKey], template: 1 }); }); const tagList = this.store.createRecord('taglist', {modelList: modelList}); tagList.save().then(()=>{ this.get('notify').success('Tags Created',{ closeAfter: 5000 }); });
Then my response from the POST of my server when I call .save() on this record looks like this
.save()
POST response /taglist { "data": [{ "type": "tags", "id": "5aaa7152a243550bbef02c9b", "attributes": { "firstName": "**", "lastName": "**", "template": 1, "__id__": "5internal-model" } }, { "type": "tags", "id": "5aaa7152a243550bbef02c9d", "attributes": { "firstName": "**", "lastName": "**", "template": 1, "__id__": "7internal-model" } }, { "type": "tags", "id": "5aaa7152a243550bbef02c9c", "attributes": { "firstName": "**", "lastName": "**", "template": 1, "__id__": "6internal-model" } }, { "type": "tags", "id": "5aaa7152a243550bbef02c9e", "attributes": { "firstName": "**", "lastName": "**", "template": 1, "__id__": "8internal-model" } }] }
Which is also what a general GET to /tags from my server looks like minus the __id__ attribute of course.
GET
/tags
__id__
Just for clarity
GET response /tags { "data": [{ "type": "tags", "id": "5aaa71326de48b0b9e6297b1", "attributes": { "firstName": "**", "lastName": "**", "template": 1 } }, { "type": "tags", "id": "5aaa71326de48b0b9e6297b2", "attributes": { "firstName": "**", "lastName": "**", "template": 1 } }, { "type": "tags", "id": "5aaa71326de48b0b9e6297b3", "attributes": { "firstName": "**", "lastName": "**", "template": 1 } }, { "type": "tags", "id": "5aaa71326de48b0b9e6297b4", "attributes": { "firstName": "**", "lastName": "**", "template": 1 } }] }
Why am I getting this Ember error?
Hi Jordan. Please follow the official repo at: https://github.com/laborvoices/ember-data-save-relationships
the response does not have an id and your record does not either.
Is being thrown on thePOST
response to my serverI have a model for a
tag
Then I want to save a bunch at once so I created a bunch of these
tag
records and have ataglist
record with a relationshipWhich also has a serializer
I create this record like so
Then my response from the
POST
of my server when I call.save()
on this record looks like thisWhich is also what a general
GET
to/tags
from my server looks like minus the__id__
attribute of course.Just for clarity
Why am I getting this Ember error?