|
|
@@ -7,7 +7,6 @@ import (
|
|
|
"git.sxidc.com/go-framework/baize/convenient/binding/response"
|
|
|
"git.sxidc.com/go-framework/baize/framwork/domain"
|
|
|
"github.com/iancoleman/strcase"
|
|
|
- "reflect"
|
|
|
)
|
|
|
|
|
|
// Simple 关联的Bind参数
|
|
|
@@ -20,10 +19,10 @@ type Simple[LI any, RI any] struct {
|
|
|
// 右领域实体,注意是Entity类型
|
|
|
Right domain.Entity
|
|
|
|
|
|
- // 左表名
|
|
|
+ // 左表名,只存在单侧表,赋值空即可
|
|
|
LeftTableName string
|
|
|
|
|
|
- // 右表名
|
|
|
+ // 右表名,只存在单侧表,赋值空即可
|
|
|
RightTableName string
|
|
|
|
|
|
// URL领域相对路径,如/user/userInfo,后面会自动补充,如/user/userInfo/update
|
|
|
@@ -57,13 +56,10 @@ type Simple[LI any, RI any] struct {
|
|
|
func (simple *Simple[LI, RI]) bind(binder *binding.Binder) {
|
|
|
options := simple.options
|
|
|
|
|
|
- leftEntityType := reflect.TypeOf(simple.Left)
|
|
|
- rightEntityType := reflect.TypeOf(simple.Right)
|
|
|
-
|
|
|
- leftRelationFieldName := fmt.Sprintf("%sID", strcase.ToCamel(rightEntityType.Name()))
|
|
|
- rightRelationFieldName := fmt.Sprintf("%sID", strcase.ToCamel(leftEntityType.Name()))
|
|
|
- leftRelationColumnName := fmt.Sprintf("%s_id", strcase.ToSnake(rightEntityType.Name()))
|
|
|
- rightRelationColumnName := fmt.Sprintf("%s_id", strcase.ToSnake(leftEntityType.Name()))
|
|
|
+ leftRelationFieldName := fmt.Sprintf("%sID", simple.Right.DomainCamelName())
|
|
|
+ rightRelationFieldName := fmt.Sprintf("%sID", simple.Left.DomainCamelName())
|
|
|
+ leftRelationColumnName := fmt.Sprintf("%s_id", strcase.ToSnake(simple.Right.DomainCamelName()))
|
|
|
+ rightRelationColumnName := fmt.Sprintf("%s_id", strcase.ToSnake(simple.Left.DomainCamelName()))
|
|
|
|
|
|
if !options.disableLeft {
|
|
|
if !options.disableLeftUpdate {
|
|
|
@@ -74,7 +70,7 @@ func (simple *Simple[LI, RI]) bind(binder *binding.Binder) {
|
|
|
RequestParams: simple.LeftUpdateJsonBody,
|
|
|
Objects: []domain.Object{simple.Left},
|
|
|
ServiceFunc: Update(simple.LeftTableName, leftRelationFieldName, leftRelationColumnName,
|
|
|
- simple.RightTableName, simple.Right.DomainCNName()),
|
|
|
+ simple.RightTableName, simple.Right.DomainCNName(), rightRelationColumnName),
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
@@ -88,7 +84,7 @@ func (simple *Simple[LI, RI]) bind(binder *binding.Binder) {
|
|
|
RequestParams: simple.RightUpdateJsonBody,
|
|
|
Objects: []domain.Object{simple.Right},
|
|
|
ServiceFunc: Update(simple.RightTableName, rightRelationFieldName, rightRelationColumnName,
|
|
|
- simple.LeftTableName, simple.Left.DomainCNName()),
|
|
|
+ simple.LeftTableName, simple.Left.DomainCNName(), leftRelationColumnName),
|
|
|
})
|
|
|
}
|
|
|
}
|