Skip to content

🐛Fixed updated_at not being updated#9532

Merged
kevinansfield merged 1 commit intoTryGhost:masterfrom
kirrg001:fix-updated-at
Mar 26, 2018
Merged

🐛Fixed updated_at not being updated#9532
kevinansfield merged 1 commit intoTryGhost:masterfrom
kirrg001:fix-updated-at

Conversation

@kirrg001
Copy link
Copy Markdown
Contributor

closes #9520


The bookshelf added one breaking change: it's allow to pass custom updated_at and created_at.
We already have a protection for not being able to override the created_at date on update.
We had to add another protection to now allow to only change the updated_at property.
You can only change updated_at if you actually change something else e.g. the title of a post.

To be able to implement this check i discovered that Bookshelfs model.changed object has a tricky behaviour.
It remembers all attributes, which where changed, doesn't matter if they are valid or invalid model properties.
We had to add a line of code to avoid remembering none valid model attributes in this object.

e.g. you change tag.parent (no valid model attribute). The valid property is tag.parent_id.
If you pass tag.parent but the value has not changed (tag.parent === tag.parent_id), it will output you tag.changed.parent. But this is wrong.
Bookshelf detects changed attributes too early. Or if you think the other way around, Ghost detects valid attributes too late.
But the current earliest possible stage is the onSaving event, there is no earlier way to pick valid attributes (except of .forge, but we don't use this fn ATM).
Later: the API should transform tag.parent into tag.parent_id, but we are not using it ATM, so no need to pre-optimise.
The API already transforms post.author into post.author_id.

closes TryGhost#9520

- it contains a dependency bump of the latest Bookshelf release
- Bookshelf introduced a bug in the last release
  - see bookshelf/bookshelf#1583
  - see bookshelf/bookshelf#1798
- this has caused trouble in Ghost
  - the `updated_at` attribute was not automatically set anymore

---

The bookshelf added one breaking change: it's allow to pass custom `updated_at` and `created_at`.
We already have a protection for not being able to override the `created_at` date on update.
We had to add another protection to now allow to only change the `updated_at` property.
You can only change `updated_at` if you actually change something else e.g. the title of a post.

To be able to implement this check i discovered that Bookshelfs `model.changed` object has a tricky behaviour.
It remembers **all** attributes, which where changed, doesn't matter if they are valid or invalid model properties.
We had to add a line of code to avoid remembering none valid model attributes in this object.

e.g. you change `tag.parent` (no valid model attribute). The valid property is `tag.parent_id`.
     If you pass `tag.parent` but the value has **not** changed (`tag.parent` === `tag.parent_id`), it will output you `tag.changed.parent`. But this is wrong.
     Bookshelf detects `changed` attributes too early. Or if you think the other way around, Ghost detects valid attributes too late.
     But the current earliest possible stage is the `onSaving` event, there is no earlier way to pick valid attributes (except of `.forge`, but we don't use this fn ATM).
     Later: the API should transform `tag.parent` into `tag.parent_id`, but we are not using it ATM, so no need to pre-optimise.
     The API already transforms `post.author` into `post.author_id`.
@kevinansfield kevinansfield merged commit 7c6f690 into TryGhost:master Mar 26, 2018
@kevinansfield kevinansfield deleted the fix-updated-at branch March 26, 2018 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Post Modified Date Not Updated

2 participants