Skip to content

beforeRemove not triggered #471

Open

Description

@FilipLukac

Hello, I have this code.

model.find({id:id}).remove(function(err){ db.close(); _this.sendAllRequestsToClient(); });
Everything is ok, removing works excelent. But hook beforeRemove is not triggered. Could anyone tell me if am I doing something wrong? thanks

beforeRemove: function(next){ var _this = this; console.log('beforeRemove ok OK OK OK OK OK OK OK '); this.getTaxi(function(err,taxi){ console.log('taxi sa nasiel akopan'); taxi.reserved=0; taxi.save(); next(); }); }

Activity

  1. added this to the milestone on Mar 13, 2014
  2. dxg commented on Mar 13, 2014

    @dxg
    Collaborator

    The chained remove operates on a list of items rather than individual ones.
    Because of this, it does a batch deletion rather than instantiating every single item - and without instantiating, it can't run hooks.

    I want to fix this in 2.1.5.
    The idea is to have something like:

    .find().remove(function (err) {...}) // remove hooks fired
    .find().remove(fireHooks: false, function (err) {...}) // remove hooks not fired

    so that people can either get the default expected behaviour or the non hook running fast behaviour.

  3. FilipLukac commented on Mar 13, 2014

    @FilipLukac
    Author

    I want to delete by PK, but I dont know how and I didn't found it. I tried to model.get(id).remove(); and this didn't go well, server crashed

  4. dxg commented on Mar 14, 2014

    @dxg
    Collaborator

    .get isn't chainable at the moment; only find and a few others are.
    To delete just one item, you can:

    model.get(id, function (err, item) {
      item.remove(function (err) {
        // item removed
      });
    });
  5. FilipLukac commented on Mar 15, 2014

    @FilipLukac
    Author

    again.. Thanks !

  6. bvallelunga commented on Mar 24, 2014

    @bvallelunga

    @dxg has any progress been made on this issue?

  7. dxg commented on Mar 24, 2014

    @dxg
    Collaborator

    Not yet. First I need to sort out #375 then I'll get onto this one.

  8. jacobp100 commented on Nov 4, 2014

    @jacobp100

    Maybe we could check if the model has remove callbacks as well as the optional 'don't fire remove hooks'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions