datamodel done without validators
This commit is contained in:
30
wagfarm-api/assets/fertilizer/model.go
Normal file
30
wagfarm-api/assets/fertilizer/model.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package fertilizer
|
||||
|
||||
import (
|
||||
"wagfarm-api/assets/base"
|
||||
"wagfarm-api/database"
|
||||
"wagfarm-api/taxonomy/fertilizertype"
|
||||
"wagfarm-api/taxonomy/ingredient"
|
||||
)
|
||||
|
||||
type Fertilizer struct {
|
||||
base.BoughtResource
|
||||
FertilizerTypeID uint `gorm:"not null"`
|
||||
FertilizerType fertilizertype.FertilizerType `gorm:"not null; constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
|
||||
// Association to the ingredients. This represents the composition.
|
||||
Ingredients []FertilizerIngredient `gorm:"not null; many2many:fertilizer_ingredient"`
|
||||
}
|
||||
|
||||
type FertilizerIngredient struct {
|
||||
FertilizerAssetID uint `gorm:"primaryKey"` // foreign key to the fertilizer assets
|
||||
IngredientID uint `gorm:"primaryKey"` // foreign key to the ingredient
|
||||
Amount float64 `gorm:"not null"` // amount of the ingredient
|
||||
|
||||
// Preload the ingredient details if needed.
|
||||
Ingredient ingredient.Ingredient `gorm:"not null"`
|
||||
}
|
||||
|
||||
func RegisterModels() {
|
||||
database.RegisterModel(&Fertilizer{})
|
||||
database.RegisterJoinTable(&Fertilizer{}, "Ingredients", &FertilizerIngredient{})
|
||||
}
|
||||
Reference in New Issue
Block a user