From 504f3e9bc274bcd6c7221e738802e0e5d4aef36f Mon Sep 17 00:00:00 2001 From: lishihai <dslsh@dscom> Date: 星期四, 20 六月 2024 17:07:02 +0800 Subject: [PATCH] 查询属性值和对象 通过主键ID查询 --- models/move_history.go | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-) diff --git a/models/move_history.go b/models/move_history.go index a83a53a..4d7b10d 100644 --- a/models/move_history.go +++ b/models/move_history.go @@ -19,6 +19,7 @@ OperationTypeName string `json:"operationTypeName" gorm:"type:varchar(127);not null;comment:浣滀笟绫诲瀷鍚嶇О"` //浣滀笟绫诲瀷鍚嶇О OperationId int `json:"operationId" gorm:"type:int;not null;comment:鎿嶄綔id"` //鎿嶄綔id ProductId string `json:"productId" gorm:"type:varchar(255);not null;comment:浜у搧id"` //浜у搧id + Product Material `json:"-" gorm:"foreignKey:ProductId"` //浜у搧 ProductName string `json:"productName" gorm:"type:varchar(255);not null;comment:浜у搧鍚嶇О"` //浜у搧鍚嶇О Amount decimal.Decimal `json:"amount" gorm:"type:decimal(20,2);not null;comment:鏁伴噺"` //鏁伴噺 Unit string `json:"unit" gorm:"type:char(10);not null;comment:鍗曚綅"` //鍗曚綅 @@ -94,6 +95,10 @@ db = db.Where("product_name like ?", fmt.Sprintf("%%%v%%", slf.Keyword)) } + if slf.Preload { + db = db.Model(&MoveHistory{}).Preload("Product") + } + return db } -- Gitblit v1.8.0