Skip to content

Commit

Permalink
Merge pull request #1892 from eerenyuan/master
Browse files Browse the repository at this point in the history
change logic of timestamp "update_time"
  • Loading branch information
ricardograca committed Dec 9, 2018
2 parents 4b4a420 + 1d37ed5 commit ec58b8d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
3 changes: 1 addition & 2 deletions lib/base/model.js
Expand Up @@ -643,9 +643,8 @@ ModelBase.prototype.timestamp = function(options) {
const createdAtKey = timestampKeys[0];
const updatedAtKey = timestampKeys[1];
const isNewModel = method === 'insert';
const setUpdatedAt = updatedAtKey && this.hasChanged(updatedAtKey);

if (updatedAtKey && ((isNewModel && !setUpdatedAt) || (this.hasChanged() && !setUpdatedAt))) {
if (updatedAtKey && (isNewModel || this.hasChanged()) && !this.hasChanged(updatedAtKey) ) {
attributes[updatedAtKey] = now;
}

Expand Down
6 changes: 4 additions & 2 deletions tutorials/parse-and-format.md
Expand Up @@ -9,11 +9,13 @@ methods:
Book = bookshelf.Model.extend({
tableName: 'books',
parse: function(response) {
response.tags = JSON.parse(response.tags || '[]');
if(response.tags)
response.tags = JSON.parse(response.tags);
return response;
},
format: function(attributes) {
attributes.tags = JSON.stringify(attributes.tags || []);
if(attributes.tags)
attributes.tags = JSON.stringify(attributes.tags);
return attributes;
}
});
Expand Down

0 comments on commit ec58b8d

Please sign in to comment.