From 50704892f00f4d7e0fae6d0ad906abf78be0562c Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sun, 7 Jul 2024 14:09:52 +0800 Subject: [PATCH] :bug: Fix filter with tag & category query statement --- pkg/internal/services/articles.go | 8 ++++---- pkg/internal/services/posts.go | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pkg/internal/services/articles.go b/pkg/internal/services/articles.go index 2d4abba..41354cd 100644 --- a/pkg/internal/services/articles.go +++ b/pkg/internal/services/articles.go @@ -17,15 +17,15 @@ import ( func FilterArticleWithCategory(tx *gorm.DB, alias string) *gorm.DB { prefix := viper.GetString("database.prefix") return tx.Joins(fmt.Sprintf("JOIN %sarticle_categories ON %sarticles.id = %sarticle_categories.article_id", prefix, prefix, prefix)). - Joins(fmt.Sprintf("JOIN %sarticle_categories ON %sarticle_categories.id = %sarticle_categories.category_id", prefix, prefix, prefix)). - Where(fmt.Sprintf("%sarticle_categories.alias = ?", prefix), alias) + Joins(fmt.Sprintf("JOIN %scategories ON %scategories.id = %sarticle_categories.category_id", prefix, prefix, prefix)). + Where(fmt.Sprintf("%scategories.alias = ?", prefix), alias) } func FilterArticleWithTag(tx *gorm.DB, alias string) *gorm.DB { prefix := viper.GetString("database.prefix") return tx.Joins(fmt.Sprintf("JOIN %sarticle_tags ON %sarticles.id = %sarticle_tags.article_id", prefix, prefix, prefix)). - Joins(fmt.Sprintf("JOIN %sarticle_tags ON %sarticle_tags.id = %sarticle_tags.category_id", prefix, prefix, prefix)). - Where(fmt.Sprintf("%sarticle_tags.alias = ?", prefix), alias) + Joins(fmt.Sprintf("JOIN %stags ON %stags.id = %sarticle_tags.tag_id", prefix, prefix, prefix)). + Where(fmt.Sprintf("%stags.alias = ?", prefix), alias) } func FilterArticleWithRealm(tx *gorm.DB, id uint) *gorm.DB { diff --git a/pkg/internal/services/posts.go b/pkg/internal/services/posts.go index cab3c65..0e511f7 100644 --- a/pkg/internal/services/posts.go +++ b/pkg/internal/services/posts.go @@ -17,15 +17,15 @@ import ( func FilterPostWithCategory(tx *gorm.DB, alias string) *gorm.DB { prefix := viper.GetString("database.prefix") return tx.Joins(fmt.Sprintf("JOIN %spost_categories ON %sposts.id = %spost_categories.post_id", prefix, prefix, prefix)). - Joins(fmt.Sprintf("JOIN %spost_categories ON %spost_categories.id = %spost_categories.category_id", prefix, prefix, prefix)). - Where(fmt.Sprintf("%spost_categories.alias = ?", prefix), alias) + Joins(fmt.Sprintf("JOIN %scategories ON %scategories.id = %spost_categories.category_id", prefix, prefix, prefix)). + Where(fmt.Sprintf("%scategories.alias = ?", prefix), alias) } func FilterPostWithTag(tx *gorm.DB, alias string) *gorm.DB { prefix := viper.GetString("database.prefix") return tx.Joins(fmt.Sprintf("JOIN %spost_tags ON %sposts.id = %spost_tags.post_id", prefix, prefix, prefix)). - Joins(fmt.Sprintf("JOIN %spost_tags ON %spost_tags.id = %spost_tags.category_id", prefix, prefix, prefix)). - Where(fmt.Sprintf("%spost_tags.alias = ?", prefix), alias) + Joins(fmt.Sprintf("JOIN %stags ON %stags.id = %spost_tags.tag_id", prefix, prefix, prefix)). + Where(fmt.Sprintf("%stags.alias = ?", prefix), alias) } func FilterPostWithRealm(tx *gorm.DB, id uint) *gorm.DB {