drudge / mongoose-timestamp

Adds createdAt and updatedAt date attributes that get auto-assigned to the most recent create/update timestamp
Other
308 stars 64 forks source link

Do not override createdAt when it is not selected #34

Closed tusbar closed 8 years ago

tusbar commented 8 years ago

This fixes this worrisome issue:

return Model
    .findById('xxx')
    .select({
        _id: true
    })
    .execAsync();
    .then(function (model) {
        return model.saveAsync()
    })
    .then(function (model) {
        // createdAt is now overridden :(
    });
tusbar commented 8 years ago

Really, 0.6 is failing.

tusbar commented 8 years ago

@drudge could you take a look at this?

tusbar commented 8 years ago

@drudge if you’re not available to maintain this, could you give me the access to do so?

drudge commented 8 years ago

I'm not sure I agree that createdAt shouldn't be created just because it wasn't selected.

tusbar commented 8 years ago

Really? Why?

createdAt is supposed to represent the document’s creation date. When you update a document where only a few properties have been selected, you don’t expect the document’s creation date to change, do you?

tusbar commented 8 years ago

Useless as https://github.com/Automattic/mongoose/pull/4351 was merged and released.

lchenay commented 8 years ago

Sadly, this is required for user who can't upgrade to latest Mongoose. Our createdAt are wrong since, some code do partial select, and so createdAt is overwritten with an update date.

tusbar commented 8 years ago

@lchenay the patch is easy – just fork, add the this.isSelected(createdAt) and use your fork, not sure that this repository will get much activity as this was open more than 6 months ago.