My server returns JSON like below and I cannot change it into sideloading style.
{
"owner": {
"id": 293,
"servers": [{
"id": 32,
"hostname": "host1",
"networks": [ {
"id": 1234,
"ip": 10.10.10.10
}, {
"id": 5678,
"ip": 10.10.20.10
}]
}, {
"id": 33,
"hostname": "host2",
"networks": [ {
"id": 1234,
"ip": 10.10.10.11
}, {
"id": 5678,
"ip": 10.10.20.11
}]
}]
}
}
There is one and only API endpoint for serving above single JSON, and for it, I written three models - owner, server, network - setup like below:
network:
import DS from 'ember-data';
export default DS.Model.extend({
servers: DS.hasMany('server'),
});
server:
import DS from 'ember-data';
export default DS.Model.extend({
hostname: DS.attr('string'),
owner: DS.belongsTo('owner', {async: true}),
networks: DS.hasMany('network', {async: true}),
});
owner:
import DS from 'ember-data';
export default DS.Model.extend({
servers: DS.hasMany('server', {async: true}),
});
Serializer for owner and server like this:
import TestSerializer from './test';
import DS from 'ember-data';
export default TestSerializer.extend(DS.EmbeddedRecordsMixin, {
attrs: {
servers: { embedded: 'always' },
}
});
import TestSerializer from './test';
import DS from 'ember-data';
export default TestSerializer.extend(DS.EmbeddedRecordsMixin, {
attrs: {
networks: { embedded: 'always' },
}
});
when I run it without network-server relation, server-owner relation solved by serializer and it is find. but with 3 level relation, it fails with very long error:
EmberError@http://localhost:4200/assets/vendor.js:27348:15 _emberMetalCore.default.assert@http://localhost:4200/assets/vendor.js:16067:13 ember$data$lib$system$store$serializer$response$$_normalizeSerializerPayloadItem/http://localhost:4200/assets/vendor.js:76803:17 ember$data$lib$system$store$serializer$response$$_normalizeSerializerPayloadItem/http://localhost:4200/assets/vendor.js:76815:35 ember$data$lib$system$store$serializer$response$$_normalizeSerializerPayloadItem/<@http://localhost:4200/assets/vendor.js:76791:12 .eachRelationship/<@http://localhost:4200/assets/vendor.js:87742:11 Map.prototype.forEach/cb@http://localhost:4200/assets/vendor.js:29106:11 OrderedSet.prototype.forEach@http://localhost:4200/assets/vendor.js:28889:11 Map.prototype.forEach@http://localhost:4200/assets/vendor.js:29110:7 .eachRelationship@http://localhost:4200/assets/vendor.js:87741:9 ember$data$lib$system$store$serializer$response$$_normalizeSerializerPayloadItem@http://localhost:4200/assets/vendor.js:76785:7 ember$data$lib$system$store$serializer$response$$_normalizeSerializerPayload@http://localhost:4200/assets/vendor.js:76753:18 ember$data$lib$system$store$$Store<.push@http://localhost:4200/assets/vendor.js:84416:18 ember$data$lib$serializers$embedded$records$mixin$$EmbeddedRecordsMixin<._extractEmbeddedHasMany/<@http://localhost:4200/assets/vendor.js:86708:11 ember$data$lib$serializers$embedded$records$mixin$$EmbeddedRecordsMixin<._extractEmbeddedHasMany@http://localhost:4200/assets/vendor.js:86706:9 ember$data$lib$serializers$embedded$records$mixin$$EmbeddedRecordsMixin<._extractEmbeddedRecords/<@http://localhost:4200/assets/vendor.js:86671:17 .eachRelationship/<@http://localhost:4200/assets/vendor.js:87742:11 Map.prototype.forEach/cb@http://localhost:4200/assets/vendor.js:29106:11 OrderedSet.prototype.forEach@http://localhost:4200/assets/vendor.js:28889:11 Map.prototype.forEach@http://localhost:4200/assets/vendor.js:29110:7 .eachRelationship@http://localhost:4200/assets/vendor.js:87741:9 ember$data$lib$serializers$embedded$records$mixin$$EmbeddedRecordsMixin<._extractEmbeddedRecords@http://localhost:4200/assets/vendor.js:86664:1 ember$data$lib$serializers$embedded$records$mixin$$EmbeddedRecordsMixin<.normalize@http://localhost:4200/assets/vendor.js:86399:16 apply@http://localhost:4200/assets/vendor.js:34198:1 superWrapper@http://localhost:4200/assets/vendor.js:33836:15 ember$data$lib$serializers$rest$serializer$$RESTSerializer<.extractArray/normalizedArray<@http://localhost:4200/assets/vendor.js:77580:20 ember$data$lib$serializers$rest$serializer$$RESTSerializer<.extractArray@http://localhost:4200/assets/vendor.js:77579:33 ember$data$lib$serializers$json$serializer$$JSONSerializer<.extractFindAll@http://localhost:4200/assets/vendor.js:74872:16 ember$data$lib$serializers$json$serializer$$JSONSerializer<.extract@http://localhost:4200/assets/vendor.js:74856:16 ember$data$lib$system$store$serializer$response$$normalizeResponseHelper@http://localhost:4200/assets/vendor.js:76729:33 ember$data$lib$system$store$finders$$_findAll/http://localhost:4200/assets/vendor.js:79011:25 Backburner.prototype.run@http://localhost:4200/assets/vendor.js:10843:18 ember$data$lib$system$store$$Store<._adapterRun@http://localhost:4200/assets/vendor.js:84741:16 ember$data$lib$system$store$finders$$_findAll/<@http://localhost:4200/assets/vendor.js:79010:9 tryCatch@http://localhost:4200/assets/vendor.js:67710:14 invokeCallback@http://localhost:4200/assets/vendor.js:67725:15 publish@http://localhost:4200/assets/vendor.js:67693:9 @http://localhost:4200/assets/vendor.js:44051:7 Queue.prototype.invoke@http://localhost:4200/assets/vendor.js:11571:9 Queue.prototype.flush@http://localhost:4200/assets/vendor.js:11635:11 DeferredActionQueues.prototype.flush@http://localhost:4200/assets/vendor.js:11436:11 Backburner.prototype.end@http://localhost:4200/assets/vendor.js:10725:9 Backburner.prototype.run@http://localhost:4200/assets/vendor.js:10847:13 run@http://localhost:4200/assets/vendor.js:31688:12 ember$data$lib$adapters$rest$adapter$$RestAdapter<.ajax/http://localhost:4200/assets/vendor.js:72892:15 jQuery.Callbacks/fire@http://localhost:4200/assets/vendor.js:3346:10 jQuery.Callbacks/self.fireWith@http://localhost:4200/assets/vendor.js:3458:7 done@http://localhost:4200/assets/vendor.js:9512:5 .send/callback@http://localhost:4200/assets/vendor.js:9916:8 vendor.js:44090:9
So, Can I use EmbeddedRecordsMixin for it? or how can I get right result on this condition?
Aucun commentaire:
Enregistrer un commentaire