This commit is contained in:
laodaming
2023-09-08 14:25:47 +08:00
parent d6c43e3e94
commit b7882ef06f
2 changed files with 8 additions and 4 deletions

View File

@@ -2,8 +2,12 @@ package gmodel
import "context"
func (p *FsProductModel) FindOne(ctx context.Context, id int64) (resp *FsProduct, err error) {
err = p.db.WithContext(ctx).Model(&FsProduct{}).Where("`id` = ? ", id).First(&resp).Error
func (p *FsProductModel) FindOne(ctx context.Context, id int64, fields ...string) (resp *FsProduct, err error) {
db := p.db.WithContext(ctx).Model(&FsProduct{}).Where("`id` = ? ", id)
if len(fields) != 0 {
db = db.Select(fields[0])
}
err = db.Take(&resp).Error
return resp, err
}
func (p *FsProductModel) FindOneBySn(ctx context.Context, sn string, fields ...string) (resp *FsProduct, err error) {