Closed 20Aditya closed 3 years ago
I have 2 tables GotestBusinessEntity and StatusBusinessEntity
GotestBusinessEntity
StatusBusinessEntity
GotestBusinessEntity looks like this:
type GotestBusinessEntity struct { Id *string `gorm:"primary_key"` Name *string Qtype *string ExternalBusinessObjectId1 *int32 ExternalBusinessObjectId2 *string StatusBusinessEntityUid *uint32 `gorm:"foreignKey:uid;constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"` Status *StatusBusinesEntity `gorm:"foreignKey:StatusBusinessEntityUid;association_foreignkey:StatusBusinessEntityUid;constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"` StatusHistory []StatusBusinesEntity `gorm:"foreignKey:uid;constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"` }
While StatusBusinessEntity looks like this:
type StatusBusinesEntity struct { Uid uint32 `gorm:"primaryKey"` Value *string StartDate *time.Time EndDate *time.Time GotestBusinessEntityID *string `gorm:"foreignKey:id;association_foreignkey:Uid;constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"` }
GotestBusinessEntity has one-many relationship with StatusBusinessEntity.
StatusBusinessEntityUid field stores the current status uid of the entity
StatusBusinessEntityUid
I insert my data like this:
func (db *DBClient) Save(entity *model.GotestBusinessEntity) error { jso, _ := json.Marshal(entity) fmt.Println(string(jso)) db.Db.Omit("StatusHistory").Create(entity) return nil }
StatusBusinessEntityUid gets updated but GotestBusinessEntityID foreign key doesn't get Updated. It shows null.
GotestBusinessEntityID
What is the reason behind this??
This issue has been automatically marked as stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 30 days
Your Question
I have 2 tables
GotestBusinessEntity
andStatusBusinessEntity
GotestBusinessEntity
looks like this:While
StatusBusinessEntity
looks like this:What's expected
GotestBusinessEntity
has one-many relationship withStatusBusinessEntity
.StatusBusinessEntityUid
field stores the current status uid of the entityI insert my data like this:
The Issue
StatusBusinessEntityUid
gets updated butGotestBusinessEntityID
foreign key doesn't get Updated. It shows null.What is the reason behind this??