diff --git a/common/database.go b/common/database.go index 75e5937..a67e7a5 100644 --- a/common/database.go +++ b/common/database.go @@ -162,10 +162,6 @@ func DummyPopulateDB(test_db *gorm.DB) { checkErr(test_db.Model(&proj_A).Association("Simulation").Append(&simn_A).Error) checkErr(test_db.Model(&proj_B).Association("Simulation").Append(&simn_A).Error) - // User HM Files - checkErr(test_db.Model(&usr_A).Association("Files").Append(&file_A).Error) - checkErr(test_db.Model(&usr_A).Association("Files").Append(&file_B).Error) - // Simulation HM SimModel, SimModel BT Simulation checkErr(test_db.Model(&smo_A).Association("BelongsToSimulation").Append(&simn_A).Error) checkErr(test_db.Model(&smo_B).Association("BelongsToSimulation").Append(&simn_A).Error) @@ -194,6 +190,10 @@ func DummyPopulateDB(test_db *gorm.DB) { // Simulator BT SimModel checkErr(test_db.Model(&smo_A).Association("BelongsToSimulator").Append(&simr_A).Error) + // 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_B).Error) + } // Erase tables and glose the testdb diff --git a/common/database_test.go b/common/database_test.go index 92d0296..2382df1 100644 --- a/common/database_test.go +++ b/common/database_test.go @@ -34,6 +34,7 @@ func TestDummyDBAssociations(t *testing.T) { var simn Simulation var usr User var vis Visualization + var widg Widget var sigs []Signal var smos []SimulationModel @@ -129,11 +130,7 @@ func TestDummyDBAssociations(t *testing.T) { "Expected to have %v Simulations. Has %v.", 2, len(simns)) } - a.NoError(db.Model(&usr).Related(&files, "Files").Error) - if len(files) != 2 { - a.Fail("User Associations", - "Expected to have %v Files. Has %v.", 2, len(files)) - } + // Visualization @@ -154,6 +151,19 @@ func TestDummyDBAssociations(t *testing.T) { "Expected to have %v Widget. Has %v.", 2, len(widgs)) } + + // Widget + a.NoError(db.Find(&widg, 1).Error, fM("Widget")) + a.EqualValues("Widget_A", vis.Name) + + + // Widget Association + a.NoError(db.Model(&widg).Related(&files, "Files").Error) + if len(files) != 2 { + a.Fail("Widget Associations", + "Expected to have %v Files. Has %v.", 2, len(files)) + } + // File a.NoError(db.Find(&file, 1).Error, fM("File")) diff --git a/common/datastructs.go b/common/datastructs.go index 24e004f..cc029ab 100644 --- a/common/datastructs.go +++ b/common/datastructs.go @@ -32,8 +32,11 @@ type File struct { //remove belongs to User relation //User User `gorm:"not null;association_autoupdate:false"` - UserID uint `gorm:"not null"` + //UserID uint `gorm:"not null"` + + //new in villasweb 2.0 SimulationModelID uint `gorm:""` + WidgetID uint `gorm:""` } type Project struct { @@ -84,7 +87,6 @@ type SimulationModel struct { //new in villasweb 2.0 (for CIM file of simulation model and other model file formats) Files []File `gorm:""` - } type User struct { @@ -97,7 +99,9 @@ type User struct { Projects []Project `gorm:"association_autoupdate:false"` Simulations []Simulation `gorm:"association_autoupdate:false"` - Files []File `gorm:""` + + //remove has many files relation + //Files []File `gorm:""` } type Visualization struct { @@ -139,4 +143,6 @@ type Widget struct { IsLocked bool `gorm:"default:false"` CustomProperties postgres.Jsonb // TODO: default value? VisualizationID uint + //new in villasweb 2.0 + Files []File `gorm:""` }