Files
artalkjs/internal/entity/comment.go
T
qwqcode ec6d2b2e60 fix(db/migrator): remove foreign key constraints and better root_id generation (#835)
Add function to delete all foreign key constraints when migration.

Leave relationship maintenance to the program and reduce the difficulty of database management. Because there are many different DBs and the implementation of foreign keys may be different, and the DB may not support foreign keys, so don't rely on the foreign key function of the DB system.
2024-04-14 23:46:22 +08:00

41 lines
812 B
Go

package entity
import (
"gorm.io/gorm"
)
type Comment struct {
gorm.Model
Content string
PageKey string `gorm:"index;size:255"`
SiteName string `gorm:"index;size:255"`
UserID uint `gorm:"index"`
IsVerified bool `gorm:"default:false"`
UA string
IP string
Rid uint `gorm:"index"` // Parent Node ID
IsCollapsed bool `gorm:"default:false"`
IsPending bool `gorm:"default:false"`
IsPinned bool `gorm:"default:false"`
VoteUp int
VoteDown int
RootID uint `gorm:"index"` // Root Node ID (can be derived from `Rid`)
Page *Page `gorm:"foreignKey:page_key;references:key"`
User *User `gorm:"foreignKey:user_id;references:id"`
}
func (c Comment) IsEmpty() bool {
return c.ID == 0
}
func (c Comment) IsAllowReply() bool {
return !c.IsCollapsed && !c.IsPending
}