Wednesday, July 3, 2024
HomeGolangSituation with Gorm struct - Getting Assist

Situation with Gorm struct – Getting Assist


I’m engaged on a easy fowl breeding software, as a result of how else can we be taught :slight_smile:

To date its working like a attraction. i can add/edit/delete birds, the issue arrises when i attempt to add fields to attach a fowl to its mum or dad. The issue is that we dont at all times have birds of which we’ve the mother and father too. However the perfect i can provide you with is that this struct:

kind Hen struct {
	gorm.Mannequin
	RingNo   string `gorm:"not null"`
	Species  string `gorm:"not null"`
	Coloration    string `gorm:"not null"`
	■■■      string `gorm:"not null"`
	UserID   uint   `gorm:"not null"`
	Consumer     Consumer
	FatherID *uint
	Father   *Hen `gorm:"foreignKey:FatherID;default:SET NULL"`
	MotherID *uint
	Mom   *Hen `gorm:"foreignKey:MotherID;default:SET NULL"`
	Notes    []BirdNote `gorm:"foreignKey:BirdID"`
}

Basicly, what i’m making an attempt to realize is that FatherID and MotherID will be empty, however no matter i attempt, i at all times find yourself with a “violates key contraint” error :frowning:

When i make every part a string it really works. However then i’ve to manually fill within the FatherID and the MotherID. within the supreme scenario i may hyperlink the fowl to the RingNo of its father and mom, utilizing a drop down menu. (or go away it empty if i dont know the daddy and mom)

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments