fix bugs in signal methods

This commit is contained in:
Sonja Happ 2019-07-25 12:03:00 +02:00
parent a06d90d085
commit 4cf4049b40

View file

@ -48,8 +48,9 @@ func (s *Signal) addToSimulationModel() error {
} }
// adapt length of mapping // adapt length of mapping
m.InputLength = db.Model(m).Where("Direction = ?", "in").Association("InputMapping").Count() var newInputLength = db.Model(m).Where("Direction = ?", "in").Association("InputMapping").Count()
err = m.Update(m) err = db.Model(m).Update("InputLength", newInputLength).Error
} else { } else {
err = db.Model(&m).Association("OutputMapping").Append(s).Error err = db.Model(&m).Association("OutputMapping").Append(s).Error
if err != nil { if err != nil {
@ -57,8 +58,8 @@ func (s *Signal) addToSimulationModel() error {
} }
// adapt length of mapping // adapt length of mapping
m.OutputLength = db.Model(m).Where("Direction = ?", "out").Association("OutputMapping").Count() var newOutputLength = db.Model(m).Where("Direction = ?", "out").Association("OutputMapping").Count()
err = m.Update(m) err = db.Model(m).Update("OutputLength", newOutputLength).Error
} }
return err return err
} }
@ -94,8 +95,8 @@ func (s *Signal) delete() error {
} }
// Reduce length of mapping by 1 // Reduce length of mapping by 1
m.InputLength-- var newInputLength = m.InputLength - 1
err = m.Update(m) err = db.Model(m).Update("InputLength", newInputLength).Error
} else { } else {
err = db.Model(&m).Association("OutputMapping").Delete(s).Error err = db.Model(&m).Association("OutputMapping").Delete(s).Error
@ -104,8 +105,8 @@ func (s *Signal) delete() error {
} }
// Reduce length of mapping by 1 // Reduce length of mapping by 1
m.OutputLength-- var newOutputLength = m.OutputLength - 1
err = m.Update(m) err = db.Model(m).Update("OutputLength", newOutputLength).Error
} }
return err return err