fix(db): wrong relation and bad where condition

This commit is contained in:
Anhgelus Morhtuuzh 2025-05-13 16:52:04 +02:00
parent 01bafe9bf1
commit 61c7bf4567
Signed by: anhgelus
GPG key ID: CAD341EFA92DDDE5
6 changed files with 26 additions and 19 deletions

View file

@ -8,16 +8,16 @@ import (
)
type Copaing struct {
ID uint `gorm:"primarykey"`
DiscordID string `gorm:"not null"`
XP []CopaingXP `gorm:"constraint:OnDelete:SET NULL;"`
GuildID string `gorm:"not null"`
ID uint `gorm:"primarykey"`
DiscordID string `gorm:"not null"`
CopaingXPs []CopaingXP `gorm:"constraint:OnDelete:SET NULL;"`
GuildID string `gorm:"not null"`
}
type CopaingXP struct {
ID uint `gorm:"primarykey"`
XP uint `gorm:"default:0"`
CopaingID uint `gorm:"not null;constraint:OnDelete:CASCADE;"`
ID uint `gorm:"primarykey"`
XP uint `gorm:"default:0"`
CopaingID uint
GuildID string `gorm:"not null;"`
CreatedAt time.Time
}
@ -51,7 +51,7 @@ func GetCopaing(discordID string, guildID string) *Copaing {
func (c *Copaing) Load() error {
return gokord.DB.
Where("discord_id = ? and guild_id = ?", c.DiscordID, c.GuildID).
Preload("XP").
Preload("CopaingXPs").
FirstOrCreate(c).
Error
}