Prevent parent overwrites during upserts
This commit is contained in:
parent
02f844a05d
commit
dcb517e1fb
@ -89,6 +89,7 @@ func (p *Project) BeforeSave(tx *gorm.DB) error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if err := p.Validate(tx); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -358,8 +359,11 @@ func (s *State) ProjectPut(
|
||||
return nil, lookupErrorToStatus("project", err)
|
||||
}
|
||||
|
||||
// Make sure we don't have a nil value
|
||||
if err != nil {
|
||||
// If a project is found, remove the basis
|
||||
// ref to prevent update attempts
|
||||
if project != nil {
|
||||
p.Basis = nil
|
||||
} else {
|
||||
project = &Project{}
|
||||
}
|
||||
|
||||
|
||||
@ -394,8 +394,12 @@ func (s *State) TargetPut(
|
||||
return nil, lookupErrorToStatus("target", err)
|
||||
}
|
||||
|
||||
// Make sure we don't have a nil
|
||||
if err != nil {
|
||||
// If a target is found, remove the project
|
||||
// ref to prevent update attempts
|
||||
if target != nil {
|
||||
t.Project = nil
|
||||
} else {
|
||||
// Otherwise, init target for the decode
|
||||
target = &Target{}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user