How to create an object in a relationship from one to another

I have parents and children. As you would expect, the parent object hasMany Child. I can create a new Parent just fine, but I cannot get new Child objects to display on my template. According to the Chrome and Firefox Ember debugging tool, it looks like Child objects are being created correctly in the store. But new children never appear in the template.

I suppose I followed Ember docs in a letter, and yet I cannot get my code to work.

I created the following jsbin to demonstrate my situation. http://emberjs.jsbin.com/zodorule

How to create new multiply connected objects in Ember?

+4
source share
1 answer

Ember data is not a database, so setting up a relationship on one side will not automatically bind it to the other.

  var child = this.store.createRecord('Child', {name: 'Fred'});
  this.store.find('parent', 1).then(function(parent) {
    child.set('parent', parent);
    parent.get('children').then(function(children){
      children.pushObject(child);
    });
  });

Example: http://jsbin.com/xorov/1/edit

+2
source

All Articles