Lost.Router.map(function() {
this.resource('countries',{path: '/'}, function(){
this.resource('country',{path: ':country_id'},function(){
this.resource('city',{path: ':city_id'});
});
});
});
My country model is
Lost.Country = DS.Model.extend({
countryCode: DS.attr('string'),
countryName: DS.attr('string'),
places: DS.hasMany('place')
});
and my place model is
Lost.Place = DS.Model.extend({
cityName: DS.attr('string'),
country: DS.belongsTo('country')
});
In country model when I change places to place this work fine but when i keep it as places I get error
TypeError: Cannot set property 'store' of undefined
DEBUG: Ember : 1.6.0-beta.1+canary.3bcd9bdc
DEBUG: Ember Data : 1.0.0-beta.7+canary.d5562867
DEBUG: Handlebars : 1.3.0
DEBUG: jQuery : 1.11.0
UPDATED
The object returned from rails server
Acual JSON:
{
"countries":[
{
"id":1,
"countryCode":"BH",
"countryName":"Bhutan",
"places":[
{
"id":1,
"country_id":1,
"cityName":"Daga"
},
{
"id":2,
"country_id":1,
"cityName":"Ha"
}
]
}
]
}
Here is how my rails serializers looks
application_serializer.rb
class ApplicationSerializer < ActiveModel::Serializer
embed :ids, :include => true
end
country_serializer.rb
class CountrySerializer < ActiveModel::Serializer
attributes :id, :countryCode, :countryName
has_many :places
end
place_serializer
class PlaceSerializer < ActiveModel::Serializer
attributes :id, :country_id, :cityName
#belongs_to :country #commented out because gives error"undefine method belongs_to"
#if i change it to has_one gives error"stack level too deep"
end
* *Additon to anwer ** this question has been answered by @kingpin2k as a part of answer if you are new developer like me instead of writing your own normalizeAttribute function I think it will be better to use already exsisting normalizeAtrribute function in DS.RESTAdapter present in ember-data. less error prone. Just copy pasting it worked for me
Ember Data : 1.0.0-beta.6
App.ApplicationAdapter = DS.RESTAdapter.extend();- Kingpin2kplacesshould match whatever the key name is on the model definition. - Kingpin2k