ember.js - EmbeddedRecordsMixin not working as expected, what am I missing? -
i'm trying use embedded records in ember data , think i'm missing fundamental.
i have 2 models
app/models/video.js:
export default ds.model.extend({ title: ds.attr('string'), transcriptions: ds.hasmany('transcription', { embedded: 'always' }) }); app/models/transcription.js:
export default ds.model.extend({ video: ds.belongsto('video') }); i have custom serializer app/serializers/video.js:
export default ds.restserializer.extend(ds.embeddedrecordsmixin, { attrs:{ transcriptions: { embedded: 'always' } }, extractsingle: function (store, type, payload, id) { var data = payload.data; return { id: data._id, title: data.title, transcriptions: [{ id: "1" }] } } }); i expect result in video model being populated transcriptions being array of transcription object instead following error:
"error while processing route: videos.show" "assertion failed: ember data expected number or string represent record(s) in
transcriptionsrelationship instead found object. if polymorphic relationship please specifytypekey. if embedded relationship please includeds.embeddedrecordsmixin, specifytranscriptionsproperty in serializer's attrs object."
any suggestions of i'm doing wrong here appreciated.
update: solution modify custom serializer following:
export default ds.restserializer.extend(ds.embeddedrecordsmixin, { attrs:{ transcriptions: { embedded: 'always' } }, extractsingle: function (store, type, payload, id) { var data = payload.data; var videopayload = { id: data._id, title: data.title, transcriptions: [{ id: "1" }] }; return this._super(store, type, videopayload, id); } }
the problem fact you're reimplementing extractsingle yourself.
you should call this.super if you're doing this..
in extractsingle on rest serializer calls normalize function - normalise function embeddedrecordsmixin it's work.
because you're not calling either this.super or manually calling this.normalize miss out on mixin doing.
Comments
Post a Comment