From 628f1b4acaac1d2bf373b7008f2e0c070fd64ae5 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Sun, 30 Apr 2023 02:16:32 -0400 Subject: [PATCH] fix: update model relationships --- model/account.go | 4 ++-- model/key.go | 5 +++-- model/key_challenge.go | 7 ++++--- model/login_session.go | 7 ++++--- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/model/account.go b/model/account.go index c5fcce2..7086581 100644 --- a/model/account.go +++ b/model/account.go @@ -12,6 +12,6 @@ type Account struct { Password *string CreatedAt time.Time UpdatedAt time.Time - LoginTokens []LoginSession `gorm:"references:ID"` - Keys []Key `gorm:"references:ID"` + LoginTokens []LoginSession + Keys []Key } diff --git a/model/key.go b/model/key.go index e3d37d2..247b1a5 100644 --- a/model/key.go +++ b/model/key.go @@ -7,8 +7,9 @@ import ( type Key struct { gorm.Model - ID uint `gorm:"primaryKey"` - Account Account `gorm:"references:ID"` + ID uint `gorm:"primaryKey"` + AccountID uint + Account Account PublicKey string PrivateKey string CreatedAt time.Time diff --git a/model/key_challenge.go b/model/key_challenge.go index bda8f34..1655a66 100644 --- a/model/key_challenge.go +++ b/model/key_challenge.go @@ -7,8 +7,9 @@ import ( type KeyChallenge struct { gorm.Model - ID uint `gorm:"primaryKey"` - Account Account `gorm:"foreignKey:AccountID"` - Challenge string `gorm:"not null"` + ID uint `gorm:"primaryKey"` + AccountID uint + Account Account + Challenge string `gorm:"not null"` Expiration time.Time } diff --git a/model/login_session.go b/model/login_session.go index d8232f2..6e4b8d2 100644 --- a/model/login_session.go +++ b/model/login_session.go @@ -7,9 +7,10 @@ import ( type LoginSession struct { gorm.Model - ID uint `gorm:"primaryKey"` - Token string `gorm:"uniqueIndex"` - Account Account `gorm:"foreignKey:AccountID"` + ID uint `gorm:"primaryKey"` + AccountID uint + Token string `gorm:"uniqueIndex"` + Account Account Expiration time.Time CreatedAt time.Time UpdatedAt time.Time