jeudi 4 février 2016

Users are not being related to group record (sails.js, ember.js)

I am having an issue where the relationship between the group and users. They are not being created but the group record is being saved on the backend.

Here is the model on Sails.js for User

module.exports = {
    attributes: {
        groups : {
            collection: 'group',
            via: 'users',
            dominant: true
        }
    }
};

Here is the model on Sails.js for Group

module.exports = {

    attributes: {
        users: {
            collection: 'user',
            via: 'groups'
        }
  }
};

Here is the ember Group model

export default DS.Model.extend({
    users: DS.hasMany('user', {async: true, inverse: null}),
});

Here is the ember User model

export default DS.Model.extend({
    groups: DS.hasMany('group', {async:true, inverse:null}),
});

Here is where I am creating the record and trying to persist the record onto sails. (users is an array of userId strings).

var groupRecord = this.store.createRecord('group');
users.forEach(function(userId) {
    _this.store.find('user', userId).then(function(user) {
        groupRecord.get('users').addObject(user);
    });
});

groupRecord.save().then(function(success) {}, function(error) {});




Aucun commentaire:

Enregistrer un commentaire