🐛 Fix category filter
This commit is contained in:
parent
e37238436f
commit
3c7ae284ac
@ -129,15 +129,12 @@ func FilterPostWithUserContext(tx *gorm.DB, user *authm.Account) *gorm.DB {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func FilterPostWithCategory(tx *gorm.DB, alias string) *gorm.DB {
|
func FilterPostWithCategory(tx *gorm.DB, alias string) *gorm.DB {
|
||||||
subQuery := tx.Table("posts").
|
aliases := strings.Split(alias, ",")
|
||||||
Select("DISTINCT posts.id").
|
return tx.Joins("JOIN post_categories ON posts.id = post_categories.post_id").
|
||||||
Joins("JOIN post_categories ON posts.id = post_categories.post_id").
|
|
||||||
Joins("JOIN categories ON categories.id = post_categories.category_id").
|
Joins("JOIN categories ON categories.id = post_categories.category_id").
|
||||||
Where("categories.alias IN ?", strings.Split(alias, ","))
|
Where("categories.alias IN ?", aliases).
|
||||||
|
Group("posts.id").
|
||||||
return tx.Table("(?) as cateogry_subquery", subQuery).
|
Having("COUNT(DISTINCT categories.id) = ?", len(aliases))
|
||||||
Joins("JOIN posts ON posts.id = category_subquery.id").
|
|
||||||
Order("posts.published_at DESC")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func FilterPostWithTag(tx *gorm.DB, alias string) *gorm.DB {
|
func FilterPostWithTag(tx *gorm.DB, alias string) *gorm.DB {
|
||||||
|
Loading…
Reference in New Issue
Block a user