vendredi 23 octobre 2015

One-to-many relationships with Ember/Sails

I have a simple Ember app I've recently migrated from Rails to Sails. Under Rails, I had no trouble setting up one-to-many relationships. But with Sails, I'm getting errors when I try to assign them using the same Ember code:

addPerson(deptid) {
    var newID = Math.random().toString(16).slice(2);
    var newRecord = this.store.createRecord('person', {
        name: "New Person",
        id: newID
    });
    newRecord.save();

    this.store.find('department', deptid).then(function (destinationDept) {
        destinationDept.get('persons').pushObject(newRecord);
    });
},

My Sails model for department looks like this:

module.exports = {

  attributes: {
    name : { type: 'string' },
    owner : {
        model: 'company'
    },
    persons : {
        collection: 'person',
        via: 'owner'
    }
  }
};

The Ember error in the console seems to have to do with didUpdateId. I can inspect the store via the Sails API and see that relationships have not been set.




Aucun commentaire:

Enregistrer un commentaire