diff --git a/.idea/GOHCache.xml b/.idea/GOHCache.xml
index bb01b14..4c81551 100644
--- a/.idea/GOHCache.xml
+++ b/.idea/GOHCache.xml
@@ -101,6 +101,13 @@
+
+
+
+
+
+
+
@@ -150,6 +157,13 @@
+
+
+
+
+
+
+
@@ -164,6 +178,34 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -438,15 +566,21 @@
+
+
+
+
+
+
diff --git a/crud/curd.go b/crud/curd.go
index f035182..ba135d2 100644
--- a/crud/curd.go
+++ b/crud/curd.go
@@ -212,14 +212,14 @@ func (c Crud[R]) ClearField(req any, delField []string, subField ...map[string]a
}
// ClearFieldPage -------------------------- 原ClearFieldPage对应实现:清理参数+分页查询 --------------------------
-func (c Crud[R]) ClearFieldPage(ctx ctx, req any, delField []string, where any, page *Paginate, order any, with bool) (items []*R, total int64, err error) {
+func (c Crud[R]) ClearFieldPage(ctx ctx, req any, delField []string, where any, page *Paginate, order any, with string) (items []*R, total int64, err error) {
// 1. 清理请求参数
filterMap := c.ClearField(req, delField)
// 2. 初始化GORM查询
db := c.Dao.Ctx(ctx)
- if with {
- db = db.Preload("*") // GORM 关联查询全部,对应GF的WithAll()
+ if with != "" {
+ db = db.Preload(with) // GORM 关联查询全部,对应GF的WithAll()
}
// 3. 构建查询条件
@@ -250,12 +250,12 @@ func (c Crud[R]) ClearFieldPage(ctx ctx, req any, delField []string, where any,
}
// ClearFieldList -------------------------- 原ClearFieldList对应实现:清理参数+列表查询(不分页) --------------------------
-func (c Crud[R]) ClearFieldList(ctx ctx, req any, delField []string, where any, order any, with bool) (items []*R, err error) {
+func (c Crud[R]) ClearFieldList(ctx ctx, req any, delField []string, where any, order any, with string) (items []*R, err error) {
filterMap := c.ClearField(req, delField)
db := c.Dao.Ctx(ctx).Model(new(R))
- if with {
- db = db.Preload("*")
+ if with != "" {
+ db = db.Preload(with)
}
if where != nil {
db = db.Where(where)
@@ -269,13 +269,13 @@ func (c Crud[R]) ClearFieldList(ctx ctx, req any, delField []string, where any,
}
// ClearFieldOne -------------------------- 原ClearFieldOne对应实现:清理参数+单条查询 --------------------------
-func (c Crud[R]) ClearFieldOne(ctx ctx, req any, delField []string, where any, order any, with bool) (item *R, err error) {
+func (c Crud[R]) ClearFieldOne(ctx ctx, req any, delField []string, where any, order any, with string) (item *R, err error) {
item = new(R)
filterMap := c.ClearField(req, delField)
db := c.Dao.Ctx(ctx).Model(item)
- if with {
- db = db.Preload("*")
+ if with != "" {
+ db = db.Preload(with)
}
if where != nil {
db = db.Where(where)
@@ -371,7 +371,7 @@ func (c Crud[R]) ArrayField(ctx ctx, where any, field any) []interface{} {
}
// FindPri -------------------------- 原FindPri对应实现:按主键查询单条记录 --------------------------
-func (c Crud[R]) FindPri(ctx ctx, primaryKey any, with bool) (model *R) {
+func (c Crud[R]) FindPri(ctx ctx, primaryKey any, with string) (model *R) {
model = new(R)
db := c.Dao.Ctx(ctx).Model(model)
pk := c.Dao.PrimaryKey()
@@ -379,8 +379,8 @@ func (c Crud[R]) FindPri(ctx ctx, primaryKey any, with bool) (model *R) {
if pk == "" {
panic("主键字段未配置")
}
- if with {
- db = db.Preload("*")
+ if with != "" {
+ db = db.Preload(with)
}
// 按主键查询
@@ -392,12 +392,12 @@ func (c Crud[R]) FindPri(ctx ctx, primaryKey any, with bool) (model *R) {
}
// -------------------------- 原First对应实现:按条件查询第一条记录 --------------------------
-func (c Crud[R]) First(ctx ctx, where any, order any, with bool) (model *R) {
+func (c Crud[R]) First(ctx ctx, where any, order any, with string) (model *R) {
model = new(R)
db := c.Dao.Ctx(ctx).Model(model)
- if with {
- db = db.Preload("*")
+ if with != "" {
+ db = db.Preload(with)
}
if where != nil {
db = db.Where(where)
@@ -424,11 +424,11 @@ func (c Crud[R]) Exists(ctx ctx, where any) (exists bool) {
}
// -------------------------- 原All对应实现:查询所有符合条件的记录 --------------------------
-func (c Crud[R]) All(ctx ctx, where any, order any, with bool) (items []*R) {
+func (c Crud[R]) All(ctx ctx, where any, order any, with string) (items []*R) {
db := c.Dao.Ctx(ctx).Model(new(R))
- if with {
- db = db.Preload("*")
+ if with != "" {
+ db = db.Preload(with)
}
if where != nil {
db = db.Where(where)
@@ -487,7 +487,7 @@ func (c Crud[R]) UpdatePri(ctx ctx, primaryKey any, data any) (count int64) {
}
// -------------------------- 原Paginate对应实现:分页查询 --------------------------
-func (c Crud[R]) Paginate(ctx context.Context, where any, p Paginate, with bool, order any) (items []*R, total int64) {
+func (c Crud[R]) Paginate(ctx context.Context, where any, p Paginate, with string, order any) (items []*R, total int64) {
db := c.Dao.Ctx(ctx).Model(new(R))
// 1. 构建查询条件
@@ -501,8 +501,8 @@ func (c Crud[R]) Paginate(ctx context.Context, where any, p Paginate, with bool,
}
// 3. 关联查询
- if with {
- db = db.Preload("*")
+ if with != "" {
+ db = db.Preload(with)
}
// 4. 排序