Skip to content

Commit

Permalink
Merge 5aa6174 into 7ed4138
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamincanac committed Dec 17, 2018
2 parents 7ed4138 + 5aa6174 commit f3454d9
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/Lucid/Model/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ class Model extends BaseModel {
* Sets `created_at` column on the values object.
*
* Note: This method will mutate the original object
* by adding a new key/value pair.
* by adding a new key/value pair if undefined.
*
* @method _setCreatedAt
*
Expand All @@ -529,7 +529,7 @@ class Model extends BaseModel {
*/
_setCreatedAt (values) {
const createdAtColumn = this.constructor.createdAtColumn
if (createdAtColumn) {
if (createdAtColumn && !values[createdAtColumn]) {
values[createdAtColumn] = this._getSetterValue(createdAtColumn, new Date())
}
}
Expand All @@ -546,9 +546,9 @@ class Model extends BaseModel {
*
* @private
*/
_setUpdatedAt (values) {
_setUpdatedAt (values, onInsert) {
const updatedAtColumn = this.constructor.updatedAtColumn
if (updatedAtColumn) {
if (updatedAtColumn && ((onInsert && !values[updatedAtColumn]) || !onInsert)) {
values[updatedAtColumn] = this._getSetterValue(updatedAtColumn, new Date())
}
}
Expand Down Expand Up @@ -593,7 +593,7 @@ class Model extends BaseModel {
* Set timestamps
*/
this._setCreatedAt(this.$attributes)
this._setUpdatedAt(this.$attributes)
this._setUpdatedAt(this.$attributes, true)
this._formatDateFields(this.$attributes)

const query = this.constructor.query()
Expand Down

0 comments on commit f3454d9

Please sign in to comment.