🐛Fixed updated_at not being updated#9532
Merged
kevinansfield merged 1 commit intoTryGhost:masterfrom Mar 26, 2018
Merged
Conversation
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`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
closes #9520
updated_atattribute was not automatically set anymoreThe bookshelf added one breaking change: it's allow to pass custom
updated_atandcreated_at.We already have a protection for not being able to override the
created_atdate on update.We had to add another protection to now allow to only change the
updated_atproperty.You can only change
updated_atif you actually change something else e.g. the title of a post.To be able to implement this check i discovered that Bookshelfs
model.changedobject 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 istag.parent_id.If you pass
tag.parentbut the value has not changed (tag.parent===tag.parent_id), it will output youtag.changed.parent. But this is wrong.Bookshelf detects
changedattributes too early. Or if you think the other way around, Ghost detects valid attributes too late.But the current earliest possible stage is the
onSavingevent, 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.parentintotag.parent_id, but we are not using it ATM, so no need to pre-optimise.The API already transforms
post.authorintopost.author_id.