Embedded Record is not getting loaded in Ember.js
- by Venky
Following is the JSON data I am trying to load using ember-data:
{
"product" : [
{
"id" : 1,
"name" : "product1",
"master" : {
"id" : 1,
"name" : "product1",
"images" : [
{
"id" : 1,
"productUrl" : "/images/product1_1.jpg"
},
{
"id" : 2,
"productUrl" : "/images/product1_2.jpg"
}
]
}
},
{
"id" : 2,
"name" : "product2",
"master" : {
"id" : 2,
"name" : "product2",
"images" : [
{
"id" : 3,
"productUrl" : "/images/product2_1.jpg"
},
{
"id" : 4,
"productUrl" : "/images/product2_2.jpg"
}
]
}
}
]
}
The models are as follows:
App.Product = DS.Model.extend
name: DS.attr('string')
description: DS.attr('string')
master: DS.belongsTo('master')
App.Master = DS.Model.extend
images: DS.hasMany('image')
App.Image = DS.Model.extend
productUrl: DS.attr('string')
The Application Serializer code is as follows:
App.ApplicationSerializer = DS.ActiveModelSerializer.extend(DS.EmbeddedRecordsMixin,
attrs: {
images: { embedded : 'always' }
master: { embedded : 'always' }
}
)
The problem is that the "master" model records are being returned empty. I am not sure, where I am going wrong.
I am using the following platform configuration:
ember-source (1.4.0)
ember-data-source (1.0.0.beta.7)
ember-rails (0.15.0)
Rails (4.1.0)
Thanks