I am facing some issues with my serialization of model. Below is a detailed code which will show how my current model and corresponding serializers look.
-
User model
export default Model.extend({ name: attr('string'), accounts: hasMany('account', {async: false}) });
-
Account model
export default Model.extend({ type: attr('string'), transactions: hasMany('transaction') })
-
Transaction model
export default Model.extend({ date: attr('string'), amount: attr('number') })
So basically its a hasMany within another hasMany.
Serializers looks like this:
-
base serializer:
export default BaseSerializer.extend({ keyForAttribute(key) { return key.underscore(); }, keyForRelationship(key, relationship) { return key.underscore(); } });
-
User serializer:
export default BaseSerializer.extend(DS.EmbeddedRecordsMixin, { attrs: { account: { embedded: 'always' } } });
-
Account serializer:
export default BaseSerializer.extend(DS.EmbeddedRecordsMixin, { attrs: { transaction: { embedded: 'always' } } });
Now when I am invoking api call which gives me a json response where user model has a property named as accounts: which internally have another property called as transactions, I am expecting them to serialize but somehow its not working. have I done anything wrong here? Please advise as I am new to ember and still learning it.
Aucun commentaire:
Enregistrer un commentaire