scottwrobinson / camo

A class-based ES6 ODM for Mongo-like databases.
556 stars 80 forks source link

pre save hook does not save modifications #80

Open SteveEmmerich opened 8 years ago

SteveEmmerich commented 8 years ago

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?

michaeljota commented 8 years ago

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

caseyWebb commented 7 years ago

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