fix(db): wrong relation and bad where condition
This commit is contained in:
parent
01bafe9bf1
commit
61c7bf4567
6 changed files with 26 additions and 19 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue