camo icon indicating copy to clipboard operation
camo copied to clipboard

pre save hook does not save modifications

Open SteveEmmerich opened this issue 9 years ago • 2 comments

When making changed to the instance in the pre save hook the changes are not saved to the db. example (pseudo code):

class Dog extends Document {
  constructor() {
    super();
    this.name = String;
  }
  preSave()
  {
    this.name = this.name + "_dog";
  }
};

var dog = Dog.create({name: 'fido'});
dog.save();
Dog.find({})
  .then(
    function(obj)
    {
      console.log(obj.name);
    });

output: "fido"

but it should be "fido_dog"

Or was this done on purpose?

SteveEmmerich avatar Jun 28 '16 16:06 SteveEmmerich

This one it's duplicated with #43. See that for workarounds.

michaeljota avatar Jul 20 '16 20:07 michaeljota

Fixed in https://github.com/scottwrobinson/camo/commit/beb5681010e1df6baed7bb826cd342665555bd10

caseyWebb avatar Nov 10 '16 15:11 caseyWebb