✨ Preloading categories and tags
This commit is contained in:
parent
e836a97435
commit
15d8449d2e
@ -3,7 +3,7 @@ package models
|
|||||||
type Tag struct {
|
type Tag struct {
|
||||||
BaseModel
|
BaseModel
|
||||||
|
|
||||||
Alias string `json:"alias" gorm:"uniqueIndex" validate:"lowercase,alphanum,min=4,max=24"`
|
Alias string `json:"alias" gorm:"uniqueIndex" validate:"lowercase,alphanum"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
Posts []Post `json:"posts" gorm:"many2many:post_tags"`
|
Posts []Post `json:"posts" gorm:"many2many:post_tags"`
|
||||||
@ -13,7 +13,7 @@ type Tag struct {
|
|||||||
type Category struct {
|
type Category struct {
|
||||||
BaseModel
|
BaseModel
|
||||||
|
|
||||||
Alias string `json:"alias" gorm:"uniqueIndex" validate:"lowercase,alphanum,min=4,max=24"`
|
Alias string `json:"alias" gorm:"uniqueIndex" validate:"lowercase,alphanum"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
Posts []Post `json:"posts" gorm:"many2many:post_categories"`
|
Posts []Post `json:"posts" gorm:"many2many:post_categories"`
|
||||||
|
@ -54,6 +54,8 @@ func GetArticleWithAlias(tx *gorm.DB, alias string, ignoreLimitation ...bool) (m
|
|||||||
var item models.Article
|
var item models.Article
|
||||||
if err := tx.
|
if err := tx.
|
||||||
Where("alias = ?", alias).
|
Where("alias = ?", alias).
|
||||||
|
Preload("Tags").
|
||||||
|
Preload("Categories").
|
||||||
Preload("Realm").
|
Preload("Realm").
|
||||||
Preload("Author").
|
Preload("Author").
|
||||||
First(&item).Error; err != nil {
|
First(&item).Error; err != nil {
|
||||||
@ -71,6 +73,8 @@ func GetArticle(tx *gorm.DB, id uint, ignoreLimitation ...bool) (models.Article,
|
|||||||
var item models.Article
|
var item models.Article
|
||||||
if err := tx.
|
if err := tx.
|
||||||
Where("id = ?", id).
|
Where("id = ?", id).
|
||||||
|
Preload("Tags").
|
||||||
|
Preload("Categories").
|
||||||
Preload("Realm").
|
Preload("Realm").
|
||||||
Preload("Author").
|
Preload("Author").
|
||||||
First(&item).Error; err != nil {
|
First(&item).Error; err != nil {
|
||||||
|
@ -62,6 +62,8 @@ func GetPostWithAlias(tx *gorm.DB, alias string, ignoreLimitation ...bool) (mode
|
|||||||
var item models.Post
|
var item models.Post
|
||||||
if err := tx.
|
if err := tx.
|
||||||
Where("alias = ?", alias).
|
Where("alias = ?", alias).
|
||||||
|
Preload("Tags").
|
||||||
|
Preload("Categories").
|
||||||
Preload("Realm").
|
Preload("Realm").
|
||||||
Preload("Author").
|
Preload("Author").
|
||||||
Preload("ReplyTo").
|
Preload("ReplyTo").
|
||||||
@ -83,6 +85,8 @@ func GetPost(tx *gorm.DB, id uint, ignoreLimitation ...bool) (models.Post, error
|
|||||||
var item models.Post
|
var item models.Post
|
||||||
if err := tx.
|
if err := tx.
|
||||||
Where("id = ?", id).
|
Where("id = ?", id).
|
||||||
|
Preload("Tags").
|
||||||
|
Preload("Categories").
|
||||||
Preload("Realm").
|
Preload("Realm").
|
||||||
Preload("Author").
|
Preload("Author").
|
||||||
Preload("ReplyTo").
|
Preload("ReplyTo").
|
||||||
|
Loading…
Reference in New Issue
Block a user