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