From aeed976c2999e2cea097cdee38d8baeefe323f3d Mon Sep 17 00:00:00 2001 From: liujiandao <274878379@qq.com> Date: 星期六, 30 三月 2024 16:15:59 +0800 Subject: [PATCH] 修改 --- models/operation_details.go | 10 +++++++++- 1 files changed, 9 insertions(+), 1 deletions(-) diff --git a/models/operation_details.go b/models/operation_details.go index 8517d8c..0434ac9 100644 --- a/models/operation_details.go +++ b/models/operation_details.go @@ -18,6 +18,11 @@ Amount decimal.Decimal `json:"amount" gorm:"type:decimal(20,2);not null;comment:鏁伴噺"` //鏁伴噺 //Unit string `json:"unit" gorm:"type:varchar(31);comment:鍗曚綅"` //鍗曚綅 Product Material `json:"product" gorm:"foreignKey:ProductId;references:ID"` + + FromLocationID int `json:"fromLocationId" gorm:"type:int;not null;comment:婧愪綅缃甶d"` //婧愪綅缃甶d + FromLocation Location `json:"fromLocation" gorm:"foreignKey:FromLocationID;references:Id"` //婧愪綅缃� + ToLocationID int `json:"toLocationId" gorm:"type:int;not null;comment:鐩爣浣嶇疆id"` //鐩爣浣嶇疆id + ToLocation Location `json:"toLocation" gorm:"foreignKey:ToLocationID;references:Id"` //鐩爣浣嶇疆 } OperationDetailsSearch struct { @@ -99,6 +104,9 @@ } if slf.ProductId != "" { db = db.Where("product_id = ?", slf.ProductId) + } + if slf.Preload { + db = db.Preload("Product") } return db @@ -207,7 +215,7 @@ if slf.PageNum*slf.PageSize > 0 { db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize) } - if err := db.Preload("Product").Find(&records).Error; err != nil { + if err := db.Find(&records).Error; err != nil { return records, fmt.Errorf("find records err: %v", err) } -- Gitblit v1.8.0