@snkani wrote:
How do I make nested model work?
App.Router.map(function () { this.resource('parents', {path: '/'}, function(){ this.resource('children1', {path: ':id'}, function () { this.resource('children2', {path: ':id'}) }); }); }); App.ParentsRoute = Ember.Route.extend({ model: function () { return this.store.find('parent'); } }); App.Children1Route = Ember.Route.extend({ model: function (param) { var _model = this.store.find('parent', param.id); return _model; } }); App.Children2Route = Ember.Route.extend({ model: function (param) { var _model = this.store.find('children1', param.id); return _model; } }); App.Parent = DS.Model.extend({ title: DS.attr('string'), subTitle: DS.attr('string'), childrens1: DS.hasMany('children1', {async: true}) }).reopenClass({ FIXTURES: [ { id: 1, title: 'OA', subTitle: 'denotes the amount spent' , childrens1: [1,2,3] }, { id: 2, title: 'OQ', subTitle: 'denotes the qty' , childrens1: [] }, { id: 2, title: 'RA', subTitle: 'denotes the coupon/redeem amount' , childrens1: [] } ] }); App.Children1 = DS.Model.extend({ title: DS.attr('string'), type: DS.attr('string'), parent: DS.belongsTo('parent'), childrens2: DS.hasMany('children2', {async: true}) }).reopenClass({ FIXTURES: [ { id: 1, title: 'Order amount', type: 'amount', parent: 1 , childrens2: 1 }, { id: 2, title: 'quantity', type: 'qty' , parent: 1 , childrens2: 2 }, { id: 3, title: 'Redeem', type: 'amount' , parent: 1 , childrens2: 1 } ] }); App.Children2 = DS.Model.extend({ type: DS.attr('string'), val1: DS.attr('number') }).reopenClass({ FIXTURES: [ { id: 1, type: 'amount', val1: 0 }, { id: 2, type: 'qty', val1: 0 } ] });
Please suggest if there is any better approach!
Posts: 1
Participants: 1