Wednesday, 15 May 2013

ember.js - Add second model to a route -



ember.js - Add second model to a route -

my application swimming lessons. need add together swimmers class. relationship has many in both directions. lesson can have many swimmers , swimmers can have many lessons.

from lesson route, select swimmer in drop down, list of swimmers , have action add together swimmer's id lesson's "swimmers" array.

i can't swimmers show in drop downwards field because don't think loading sec model correctly.

i open suggestions of how add together specific swimmer specific class. it's of import see available swimmers

i new both ember , programming please maintain in mind when making suggestions. give thanks you!

app.router.map(function() { this.resource('lessons', { path: '/lessons' }, function() { this.resource('lesson', { path: '/:lesson_id' }) this.route('new', { path: '/new' }) }); this.resource('swimmers', { path: '/swimmers' }, function() { this.resource('swimmer', { path: '/:swimmer_id' }) this.route('new', { path: '/new' }) }); }); app.lesson = ds.model.extend({ type: ds.attr(), name: ds.attr(), /*level: ds.attr(), there hybrid levels, leave */ instructor:ds.belongsto('instructor', {async: true}), startdate: ds.attr(), enddate: ds.attr(), capacity: ds.attr('number'), swimmers: ds.hasmany('swimmer',{async: true}), }); app.swimmer = ds.model.extend({ namefirst: ds.attr(), namelast: ds.attr(), level: ds.attr(), birthdate: ds.attr(), gender: ds.attr(), note:ds.attr(), lessons: ds.hasmany('lesson', {async: true}), }); app.lessonroute = ember.route.extend({ model: function(params) { homecoming ember.rsvp.hash({ lesson: this.store.find('lesson', params.lesson_id), swimmers: this.store.findall('swimmer') }) }, setupcontroller: function(controller, model) { controller.set('model', model.lesson); controller.set('swimmer', model.swimmer); }, });

drop downwards trying use

<div class="form-group"> <label for="lesson_swimmers" class="col-sm-2 control- label">swimmers</label> <div class="col-sm-9"> {{view ember.select content=swimmers optionlabelpath="content.fullname" class="form-control" id="lesson_swimmers"}} </div> </div>

there 2 answers question. right 1 depend on how providing model.

if arriving via transferto or linkto need utilize different approach if arriving straight via url.

@kingpin2k answers question , provides examples here,

kingpin2k's elegant solution.

ember.js relationship has-many relationships

No comments:

Post a Comment