FIX: Load categories with post revisions (#26496)

When lazy load categories is enabled, categories should be loaded with
post revisions because the categories may not be preloaded on the client
side.
This commit is contained in:
Bianca Nenciu 2024-04-08 11:33:33 +03:00 committed by GitHub
parent bd7823cc70
commit 6c2c1a43ae
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 12 additions and 3 deletions

View File

@ -74,9 +74,10 @@ export default class Post extends RestModel {
}
static loadRevision(postId, version) {
return ajax(`/posts/${postId}/revisions/${version}.json`).then((result) =>
EmberObject.create(result)
);
return ajax(`/posts/${postId}/revisions/${version}.json`).then((result) => {
result.categories?.forEach((c) => Site.current().updateCategory(c));
return EmberObject.create(result);
});
}
static hideRevision(postId, version) {

View File

@ -28,6 +28,12 @@ class PostRevision < ActiveRecord::Base
SQL
end
def categories
return [] if modifications["category_id"].blank?
@categories ||= Category.where(id: modifications["category_id"])
end
def hide!
update_column(:hidden, true)
end

View File

@ -28,6 +28,8 @@ class PostRevisionSerializer < ApplicationSerializer
:wiki,
:can_edit
has_many :categories, serializer: BasicCategorySerializer, embed: :objects
# Creates a field called field_name_changes with previous and
# current members if a field has changed in this revision
def self.add_compared_field(field)