mirror of
https://github.com/discourse/discourse.git
synced 2025-05-31 22:35:03 +08:00
FIX: TopicQuery for NULL category.topic_id
(#20664)
Our schema allows `category.topic_id` to be NULL. Null values shouldn't actually happen in production, but it is very common in tests because `Fabricate(:category)` skips creating the definition topic to improve performance. Before this commit, a NULL category.topic_id would cause all subcategory topics to be excluded from a TopicQuery result. This is because, in postgres, `NULL <> anything` is falsy. Instead, we can use `IS DISTINCT FROM`, which will return true when NULL is compared to a non-NULL value.
This commit is contained in:
@ -692,7 +692,10 @@ class TopicQuery
|
||||
result = result.where("topics.category_id IN (?)", Category.subcategory_ids(category_id))
|
||||
if !SiteSetting.show_category_definitions_in_topic_lists
|
||||
result =
|
||||
result.where("categories.topic_id <> topics.id OR topics.category_id = ?", category_id)
|
||||
result.where(
|
||||
"categories.topic_id IS DISTINCT FROM topics.id OR topics.category_id = ?",
|
||||
category_id,
|
||||
)
|
||||
end
|
||||
end
|
||||
result = result.references(:categories)
|
||||
|
Reference in New Issue
Block a user