Hi there, (this post is a duplicate to: https://github.com/emberjs/data/issues/3710 but my problem is yet not solved…) so i hope i can get your help now…
i’m trying to migrate my Ember 1.12.x App to Ember 1.13.8 and im going crazy with our JSON and Ember Data. I really need help, i tryed out so many things and no progress
I have Nested JSON Payload like this:
{
"dashboard":[
{
"elementBeanList":[
{
"fieldBeanList":[
{
"fieldName":null,
"fieldType":"java.lang.Integer"
},
{
"fieldName":null,
"fieldType":"java.lang.String"
},
{
"fieldName":null,
"fieldType":"java.lang.String"
},
{
"fieldName":null,
"fieldType":"java.lang.String"
}
],
"elementClassId":"xxx",
"elementBeanList":[
],
"count":null,
"link":"5",
"linkList":[
{
"id":"xxx",
"value":"xxx"
}
]
},
{
"fieldBeanList":[
{
"fieldName":null,
"fieldType":"java.lang.Integer"
},
{
"fieldName":null,
"fieldType":"java.lang.String"
},
{
"fieldName":null,
"fieldType":"java.lang.String"
},
{
"fieldName":null,
"fieldType":"java.lang.String"
}
],
"elementClassId":"xxx",
"elementBeanList":[
],
"count":null,
"link":"1",
"linkList":[
{
"id":"xxx",
"value":"xxx"
},
{
"id":"xxx",
"value":"xxx"
}
]
},
{
"fieldBeanList":[
{
"fieldName":null,
"fieldType":"java.lang.Integer"
},
{
"fieldName":null,
"fieldType":"java.lang.String"
},
{
"fieldName":null,
"fieldType":"java.lang.String"
},
{
"fieldName":null,
"fieldType":"java.lang.String"
}
],
"elementClassId":"xxx",
"elementBeanList":[
],
"count":null,
"link":"2",
"linkList":[
{
"id":"xxx",
"value":"xxx"
},
{
"id":"xxx",
"value":"xxx"
}
]
}
]
}
],
"titel":"Dashboard"
}
And my models:
dashboard:
export default DS.Model.extend({
elementBeanList: DS.hasMany('elementbeanlist')
});
elementbeanlist:
export default DS.Model.extend({
fieldBeanList: DS.hasMany('fieldbeanlist'),
elementBeanList: DS.hasMany('elementbeanlist', {inverse: null}),
elementClassId: DS.attr('string'),
link: DS.attr('string'),
linkList: DS.attr(),
count: DS.attr(),
});
fieldbeanlist:
export default DS.Model.extend({
fieldName:DS.attr('string'),
fieldType:DS.attr('string')
});
And i modified the serializer:
dashboardSerializer:
export default DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin,{
attrs: {
elementBeanList: { embedded: 'always' },
fieldbeanlist: { embedded: 'always' },
},
normalizePayload: function(payload) {
console.log("DashboardSerializer > normalizePayload");
if(payload.elementBeanWrapper){
payload.dashboard = payload.elementBeanWrapper;
delete payload.elementBeanWrapper;
}
return payload;
}
});
When i try transition to the Dashboard Route i get this error and dont know how to solve it!
The Error is this:
Ember Data expected a number or string to represent the record(s) in the fieldBeanList
relationship instead it found an object. If this is a polymorphic relationship please specify a type
key. If this is an embedded relationship please include the DS.EmbeddedRecordsMixin
and specify the fieldBeanList
property in your serializer’s attrs object.
And
Error: Assertion Failed: Ember Data expected a number or string to represent the record(s) in the fieldBeanList
relationship instead it found an object. If this is a polymorphic relationship please specify a type
key. If this is an embedded relationship please include the DS.EmbeddedRecordsMixin
and specify the fieldBeanList
property in your serializer’s attrs object.
So did the following changes:
export default DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin,{
primaryKey: 'elementClassId',
attrs: {
elementBeanList: { embedded: 'always' },
fieldbeanlist: { embedded: 'always' },
},
but the error is still there… Please tell me if you need more informations or something else!
Thanks in advance &best regards rocki