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
This commit is contained in:
David Taylor 2024-01-25 10:49:00 +00:00 committed by GitHub
parent 57ea56ee05
commit 1651d63204
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 7 additions and 3 deletions

View File

@ -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();