loopback-softdelete-mixin icon indicating copy to clipboard operation
loopback-softdelete-mixin copied to clipboard

destroyAll problem

Open fuzzball1980 opened this issue 9 years ago • 0 comments

Hi guys!

I have a little problem using the destroyAll on hasManay relations

The problema is that the callback is never called inside the destroyAll method of the mixins.

I have added the parameters options to the method like the definition in the destroyAll of the juggler dao.js and now it works

Model.destroyAll = function softDestroyAll(where, options, cb) {
    if (options === undefined && cb === undefined) {
      if (typeof where === 'function') {
        cb = where;
        where = {};
      }
    } else if (cb === undefined) {
      if (typeof options === 'function') {
        cb = options;
        options = {};
      }
    }

    return Model.updateAll(where, {...scrubbed, [deletedAt]: new Date(), [_isDeleted]: true
      })
      .then(result => (typeof cb === 'function') ? cb(null, result) : result)
      .catch(error => (typeof cb === 'function') ? cb(error) : Promise.reject(error));
  };

The use case where the mixins fail is the following:

User.upsert(new User(user), function(err, instance) {
      if(err) {
        return cb(error);
      }

      instance.roles.destroyAll(function (error) {
       // never enter  here
      });
});

Where RoleMapping model has SeoftDelete enabled.

I'm missing something? or is ti a real bug?

Thank you!

fuzzball1980 avatar May 31 '16 19:05 fuzzball1980