Cannot see embedded properties of model after serialization


#1

Maybe someone can help me with that. I want to get JSON object from the server response. My model “tree” contains root (“child-node”), that may contain more of “child-node” and so on. But when I try to “serialize” the response, I cannot see the inner “child-node” . As you can see I’m using EmbeddeRecordsMixin

model tree.js
export default Model.extend({
  root: belongsTo('child-node'),
  selectedNodeId: attr('string'),
  openNodesIds: attr('array')
});

serializer tree.js
export default RESTSerializer.extend(DS.EmbeddedRecordsMixin, {
  attrs: {
    root:{ embedded: 'always'  },
    openNodesIds:{ embedded: 'always' }
  }
});

model child-node.js
export default Model.extend({
  infoId: attr('string'),
  metricValues: hasMany('metric-value'),
  name: attr('string'),
  nodeType: attr('string'),
  children: hasMany('child-node')
});

serializer child-node.js
export default RESTSerializer.extend(DS.EmbeddedRecordsMixin, {
  attrs: {
    metricValues:{ embedded: 'always' },
    children:{ embedded: 'always' }
  },
  normalize(model, hash/*, prop*/) {
    // debugger
    if(hash.metricValues) {
      hash.metricValues.forEach(function (itemValue) {
        itemValue.id = itemValue.name + ' ' + hash.id;
      });
    }
	return this._super(...arguments);
  }
 }
 
 This is the response from server
 tree: {
	id: "treeId",
	openNodesIds: ["instance1", "instance2"],
	selectedNodeId: "instance",
	root: {
		id: "instance",
		infoId: null,
		metricValues: null,
		name: "instance1",
		nodeType: "instance",
		children: {
			0:{id: "instance:query_hash", name: "SQL Statements", infoId: null, nodeType: "query_hash",…}
			1:{id: "instance:sql_handle", name: "TSQL Batches", infoId: null, nodeType: "sql_handle",…}
			2:{id: "instance:database_name", name: "Databases", infoId: null, nodeType: "database_name",…}
			3:{id: "instance:program_name", name: "Programs", infoId: null, nodeType: "program_name",…}
			4:{id: "instance:username", name: "Users", infoId: null, nodeType: "username", metricValues: null,…}
			5:{id: "instance:machine_name", name: "Client Machines", infoId: null, nodeType: "machine_name",…}
		}
	}
}