mirror of
https://git.rwth-aachen.de/acs/public/villas/web-backend-go/
synced 2025-03-30 00:00:12 +01:00
change data model to use Simulator has many SimulationModels
This commit is contained in:
parent
86e380c85e
commit
2973718d86
3 changed files with 4 additions and 15 deletions
|
@ -189,9 +189,9 @@ func DummyPopulateDB(test_db *gorm.DB) {
|
||||||
checkErr(test_db.Model(&mo_A).Association("Files").Append(&file_A).Error)
|
checkErr(test_db.Model(&mo_A).Association("Files").Append(&file_A).Error)
|
||||||
checkErr(test_db.Model(&mo_A).Association("Files").Append(&file_B).Error)
|
checkErr(test_db.Model(&mo_A).Association("Files").Append(&file_B).Error)
|
||||||
|
|
||||||
// Simulator BT SimulationModel
|
// Simulator HM SimulationModels
|
||||||
checkErr(test_db.Model(&mo_A).Association("Simulator").Append(&simr_A).Error)
|
checkErr(test_db.Model(&simr_A).Association("SimulationModels").Append(&mo_A).Error)
|
||||||
checkErr(test_db.Model(&mo_B).Association("Simulator").Append(&simr_A).Error)
|
checkErr(test_db.Model(&simr_A).Association("SimulationModels").Append(&mo_B).Error)
|
||||||
|
|
||||||
// Widget HM Files
|
// Widget HM Files
|
||||||
checkErr(test_db.Model(&widg_A).Association("Files").Append(&file_A).Error)
|
checkErr(test_db.Model(&widg_A).Association("Files").Append(&file_A).Error)
|
||||||
|
|
|
@ -52,8 +52,6 @@ type SimulationModel struct {
|
||||||
StartParameters string
|
StartParameters string
|
||||||
// ID of simulation to which simulation model belongs
|
// ID of simulation to which simulation model belongs
|
||||||
SimulationID uint
|
SimulationID uint
|
||||||
// Simulator associated with simulation model
|
|
||||||
Simulator Simulator
|
|
||||||
// ID of simulator associated with simulation model
|
// ID of simulator associated with simulation model
|
||||||
SimulatorID uint
|
SimulatorID uint
|
||||||
// Mapping of output signals of the simulation model, order of signals is important
|
// Mapping of output signals of the simulation model, order of signals is important
|
||||||
|
@ -101,7 +99,7 @@ type Simulator struct {
|
||||||
// Raw properties of simulator as JSON string
|
// Raw properties of simulator as JSON string
|
||||||
RawProperties string
|
RawProperties string
|
||||||
// SimulationModels in which the simulator is used
|
// SimulationModels in which the simulator is used
|
||||||
SimulationModels []SimulationModel
|
SimulationModels []SimulationModel `gorm:"foreignkey:SimulatorID"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Visualization data model
|
// Visualization data model
|
||||||
|
|
|
@ -44,10 +44,6 @@ func (m *SimulationModel) addToSimulation() error {
|
||||||
// associate simulator with simulation model
|
// associate simulator with simulation model
|
||||||
var simltr simulator.Simulator
|
var simltr simulator.Simulator
|
||||||
err = simltr.ByID(m.SimulatorID)
|
err = simltr.ByID(m.SimulatorID)
|
||||||
err = db.Model(m).Association("Simulator").Append(&simltr).Error
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
err = db.Model(&simltr).Association("SimulationModels").Append(m).Error
|
err = db.Model(&simltr).Association("SimulationModels").Append(m).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -74,10 +70,6 @@ func (m *SimulationModel) Update(modifiedSimulationModel SimulationModel) error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
err = db.Model(m).Association("Simulator").Replace(s).Error
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
// remove simulation model from old simulator
|
// remove simulation model from old simulator
|
||||||
err = db.Model(&s_old).Association("SimulationModels").Delete(m).Error
|
err = db.Model(&s_old).Association("SimulationModels").Delete(m).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -93,7 +85,6 @@ func (m *SimulationModel) Update(modifiedSimulationModel SimulationModel) error
|
||||||
"OutputLength": modifiedSimulationModel.OutputLength,
|
"OutputLength": modifiedSimulationModel.OutputLength,
|
||||||
"InputLength": modifiedSimulationModel.InputLength,
|
"InputLength": modifiedSimulationModel.InputLength,
|
||||||
"StartParameters": modifiedSimulationModel.StartParameters,
|
"StartParameters": modifiedSimulationModel.StartParameters,
|
||||||
"SimulatorID": modifiedSimulationModel.SimulatorID,
|
|
||||||
}).Error
|
}).Error
|
||||||
|
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Add table
Reference in a new issue