From 1651d6320412d8361b78a2b5b8dd863f4fde01fb Mon Sep 17 00:00:00 2001 From: David Taylor Date: Thu, 25 Jan 2024 10:49:00 +0000 Subject: [PATCH] FIX: Allow `category` to be set on `topic` model instances (#25416) Some parts of our code (e.g. some types of reviewable) set `topic.category`. In the past this would override the computed property value, but with recent Ember it raises an error. This commit adds a setter which handles the situation cleanly --- app/assets/javascripts/discourse/app/models/topic.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/discourse/app/models/topic.js b/app/assets/javascripts/discourse/app/models/topic.js index f59e5cbcb27..1794742628c 100644 --- a/app/assets/javascripts/discourse/app/models/topic.js +++ b/app/assets/javascripts/discourse/app/models/topic.js @@ -1,4 +1,4 @@ -import EmberObject from "@ember/object"; +import EmberObject, { computed } from "@ember/object"; import { alias, and, equal, notEmpty, or } from "@ember/object/computed"; import { Promise } from "rsvp"; import { resolveShareUrl } from "discourse/helpers/share-url"; @@ -214,11 +214,15 @@ const Topic = RestModel.extend({ return { type: "topic", id }; }, - @discourseComputed("category_id") - category() { + @computed("category_id") + get category() { return Category.findById(this.category_id); }, + set category(newCategory) { + this.set("category_id", newCategory?.id); + }, + @discourseComputed("url") shareUrl(url) { const user = User.current();