mirror of
https://git.rwth-aachen.de/acs/public/villas/web-backend-go/
synced 2025-03-30 00:00:12 +01:00
remove Files from User, add relation to to Widget
This commit is contained in:
parent
473abac8f4
commit
8d3f7c4fa0
3 changed files with 28 additions and 12 deletions
|
@ -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_A).Association("Simulation").Append(&simn_A).Error)
|
||||||
checkErr(test_db.Model(&proj_B).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
|
// Simulation HM SimModel, SimModel BT Simulation
|
||||||
checkErr(test_db.Model(&smo_A).Association("BelongsToSimulation").Append(&simn_A).Error)
|
checkErr(test_db.Model(&smo_A).Association("BelongsToSimulation").Append(&simn_A).Error)
|
||||||
checkErr(test_db.Model(&smo_B).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
|
// Simulator BT SimModel
|
||||||
checkErr(test_db.Model(&smo_A).Association("BelongsToSimulator").Append(&simr_A).Error)
|
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
|
// Erase tables and glose the testdb
|
||||||
|
|
|
@ -34,6 +34,7 @@ func TestDummyDBAssociations(t *testing.T) {
|
||||||
var simn Simulation
|
var simn Simulation
|
||||||
var usr User
|
var usr User
|
||||||
var vis Visualization
|
var vis Visualization
|
||||||
|
var widg Widget
|
||||||
|
|
||||||
var sigs []Signal
|
var sigs []Signal
|
||||||
var smos []SimulationModel
|
var smos []SimulationModel
|
||||||
|
@ -129,11 +130,7 @@ func TestDummyDBAssociations(t *testing.T) {
|
||||||
"Expected to have %v Simulations. Has %v.", 2, len(simns))
|
"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
|
// Visualization
|
||||||
|
|
||||||
|
@ -154,6 +151,19 @@ func TestDummyDBAssociations(t *testing.T) {
|
||||||
"Expected to have %v Widget. Has %v.", 2, len(widgs))
|
"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
|
// File
|
||||||
|
|
||||||
a.NoError(db.Find(&file, 1).Error, fM("File"))
|
a.NoError(db.Find(&file, 1).Error, fM("File"))
|
||||||
|
|
|
@ -32,8 +32,11 @@ type File struct {
|
||||||
|
|
||||||
//remove belongs to User relation
|
//remove belongs to User relation
|
||||||
//User User `gorm:"not null;association_autoupdate:false"`
|
//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:""`
|
SimulationModelID uint `gorm:""`
|
||||||
|
WidgetID uint `gorm:""`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Project struct {
|
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)
|
//new in villasweb 2.0 (for CIM file of simulation model and other model file formats)
|
||||||
Files []File `gorm:""`
|
Files []File `gorm:""`
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
|
@ -97,7 +99,9 @@ type User struct {
|
||||||
|
|
||||||
Projects []Project `gorm:"association_autoupdate:false"`
|
Projects []Project `gorm:"association_autoupdate:false"`
|
||||||
Simulations []Simulation `gorm:"association_autoupdate:false"`
|
Simulations []Simulation `gorm:"association_autoupdate:false"`
|
||||||
Files []File `gorm:""`
|
|
||||||
|
//remove has many files relation
|
||||||
|
//Files []File `gorm:""`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Visualization struct {
|
type Visualization struct {
|
||||||
|
@ -139,4 +143,6 @@ type Widget struct {
|
||||||
IsLocked bool `gorm:"default:false"`
|
IsLocked bool `gorm:"default:false"`
|
||||||
CustomProperties postgres.Jsonb // TODO: default value?
|
CustomProperties postgres.Jsonb // TODO: default value?
|
||||||
VisualizationID uint
|
VisualizationID uint
|
||||||
|
//new in villasweb 2.0
|
||||||
|
Files []File `gorm:""`
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue