🐛 Fix filter with tag & category query statement
This commit is contained in:
parent
b778822247
commit
50704892f0
@ -17,15 +17,15 @@ import (
|
|||||||
func FilterArticleWithCategory(tx *gorm.DB, alias string) *gorm.DB {
|
func FilterArticleWithCategory(tx *gorm.DB, alias string) *gorm.DB {
|
||||||
prefix := viper.GetString("database.prefix")
|
prefix := viper.GetString("database.prefix")
|
||||||
return tx.Joins(fmt.Sprintf("JOIN %sarticle_categories ON %sarticles.id = %sarticle_categories.article_id", prefix, prefix, 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)).
|
Joins(fmt.Sprintf("JOIN %scategories ON %scategories.id = %sarticle_categories.category_id", prefix, prefix, prefix)).
|
||||||
Where(fmt.Sprintf("%sarticle_categories.alias = ?", prefix), alias)
|
Where(fmt.Sprintf("%scategories.alias = ?", prefix), alias)
|
||||||
}
|
}
|
||||||
|
|
||||||
func FilterArticleWithTag(tx *gorm.DB, alias string) *gorm.DB {
|
func FilterArticleWithTag(tx *gorm.DB, alias string) *gorm.DB {
|
||||||
prefix := viper.GetString("database.prefix")
|
prefix := viper.GetString("database.prefix")
|
||||||
return tx.Joins(fmt.Sprintf("JOIN %sarticle_tags ON %sarticles.id = %sarticle_tags.article_id", prefix, prefix, 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)).
|
Joins(fmt.Sprintf("JOIN %stags ON %stags.id = %sarticle_tags.tag_id", prefix, prefix, prefix)).
|
||||||
Where(fmt.Sprintf("%sarticle_tags.alias = ?", prefix), alias)
|
Where(fmt.Sprintf("%stags.alias = ?", prefix), alias)
|
||||||
}
|
}
|
||||||
|
|
||||||
func FilterArticleWithRealm(tx *gorm.DB, id uint) *gorm.DB {
|
func FilterArticleWithRealm(tx *gorm.DB, id uint) *gorm.DB {
|
||||||
|
@ -17,15 +17,15 @@ import (
|
|||||||
func FilterPostWithCategory(tx *gorm.DB, alias string) *gorm.DB {
|
func FilterPostWithCategory(tx *gorm.DB, alias string) *gorm.DB {
|
||||||
prefix := viper.GetString("database.prefix")
|
prefix := viper.GetString("database.prefix")
|
||||||
return tx.Joins(fmt.Sprintf("JOIN %spost_categories ON %sposts.id = %spost_categories.post_id", prefix, prefix, 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)).
|
Joins(fmt.Sprintf("JOIN %scategories ON %scategories.id = %spost_categories.category_id", prefix, prefix, prefix)).
|
||||||
Where(fmt.Sprintf("%spost_categories.alias = ?", prefix), alias)
|
Where(fmt.Sprintf("%scategories.alias = ?", prefix), alias)
|
||||||
}
|
}
|
||||||
|
|
||||||
func FilterPostWithTag(tx *gorm.DB, alias string) *gorm.DB {
|
func FilterPostWithTag(tx *gorm.DB, alias string) *gorm.DB {
|
||||||
prefix := viper.GetString("database.prefix")
|
prefix := viper.GetString("database.prefix")
|
||||||
return tx.Joins(fmt.Sprintf("JOIN %spost_tags ON %sposts.id = %spost_tags.post_id", prefix, prefix, 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)).
|
Joins(fmt.Sprintf("JOIN %stags ON %stags.id = %spost_tags.tag_id", prefix, prefix, prefix)).
|
||||||
Where(fmt.Sprintf("%spost_tags.alias = ?", prefix), alias)
|
Where(fmt.Sprintf("%stags.alias = ?", prefix), alias)
|
||||||
}
|
}
|
||||||
|
|
||||||
func FilterPostWithRealm(tx *gorm.DB, id uint) *gorm.DB {
|
func FilterPostWithRealm(tx *gorm.DB, id uint) *gorm.DB {
|
||||||
|
Loading…
Reference in New Issue
Block a user