0

i have two models:

user.js

module.exports = {
attributes: {
    ...
    profile: {
        model: 'Profile'
    },
    groups: {
        collection: 'group',
        via: 'users',
        dominate: true
    },
    roles: {
        collection: 'role',
        via: 'users',
        dominate: true
    }
}};

and, group.js

module.exports = {
attributes: {
    ...
    users: {
        collection: 'user',
        via: 'groups'
    }
}};

when i try to add users to a group (when i select a group and add users to it), it works as it is supposed to,

var defer = q.defer();
    baseDbContext.single(req, 'users')
        .then(function(op){
            if(!op.status || !op.obj) {
                defer.resolve(notFound);
                return;
            }

            op.obj.users = [];
            _.each(req.users, function(item){
                op.obj.users.add(item);
            });

            op.obj.save(function(err, obj){
                if(err) defer.reject(operationResult().throwException(err));
                else defer.resolve(operationResult().succeed());
            });
        });
    return defer.promise;

but when i try to add groups to the user (when i select the user and add groups to it) it fails silently!!!

var defer = q.defer();
    baseDbContext.single(req, 'groups')
        .then(function(op){
            if(!op.status || !op.obj) {
                defer.resolve(notFound);
                return;
            }

            op.obj.groups = [];
            _.each(req.groups, function(item){
                op.obj.groups.add(item);
            });

            op.obj.save(function(err, obj){
                if(err) defer.reject(operationResult().throwException(err));
                else defer.resolve(operationResult().succeed());
            });
        });
    return defer.promise;

when i check it in sails console it shows :

throw new Error('Unknown rule: ' + ruleName);
Error: Unknown rule: dominate

this is a simple many to many insertion why would it fail? (a note about code, the function baseDbContext.single finds a object based on its id and the second parameter is for populate)

1 Answers1

0

Seems like you have a misprint, documentation says that the rule you need is writes as "dominant: true", not "dominate: true".

ftkvyn
  • 106
  • 4