ember.js - Many to Many relationship in emberfire -
i wondering wether possible create many many relationship in emberfire. i've got following models:
//employee name: ds.attr('string'), position: ds.attr('string'), accessoryposition: ds.attr('string'), education: ds.attr('string'), experience: ds.attr('string'), imgurl: ds.attr('string'), teachingin: ds.attr('string'), subjects: ds.hasmany('subject', {async: true}) //subject name: ds.attr('string'), coursedescriptionurl: ds.attr('string'), description: ds.attr('string'), examdescriptionurl: ds.attr('string'), imgurl: ds.attr('string'), sportssubject: ds.attr('boolean'), outdoorsubject: ds.attr('boolean'), commonsubject: ds.attr('boolean'), teachers: ds.hasmany('employee', {async : true})
and in employee controller:
update(subjects) { this.get('model.employee').set('subjects',subjects); this.get('model.employee').save(); }
but adds /employees endpoint. there anyway make relationship mutual speak?
you have manually add employ subjects. way like:
update(subjects) { this.get('model.employee').set('subjects', subjects); this.get('model.employee').save(); subjects.foreach(subject => { subject.get('teachers').addobject(subject); }); subjects.invoke('save'); }
array#pushobject
adds subject
if it's not in array, , array#invoke
calls save
method on every element of array.
hope helpful.
Comments
Post a Comment