Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change logic of timestamp "update_time" #1892

Merged
merged 9 commits into from
Dec 9, 2018
3 changes: 1 addition & 2 deletions lib/base/model.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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