GetModelStruct without relations
This commit is contained in:
parent
0d2c37e310
commit
af7da1ec44
@ -50,8 +50,8 @@ func TestHasOneAndHasManyAssociation(t *testing.T) {
|
|||||||
t.Errorf("Comment 2 Should have post id")
|
t.Errorf("Comment 2 Should have post id")
|
||||||
}
|
}
|
||||||
|
|
||||||
// comment3 := Comment{Content: "Comment 3", Post: Post{Title: "Title 3", Body: "Body 3"}}
|
comment3 := Comment{Content: "Comment 3", Post: Post{Title: "Title 3", Body: "Body 3"}}
|
||||||
// DB.Save(&comment3)
|
DB.Save(&comment3)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRelated(t *testing.T) {
|
func TestRelated(t *testing.T) {
|
||||||
|
@ -112,7 +112,7 @@ func (scope *Scope) generateSqlTag(field *StructField) {
|
|||||||
var pluralMapKeys = []*regexp.Regexp{regexp.MustCompile("ch$"), regexp.MustCompile("ss$"), regexp.MustCompile("sh$"), regexp.MustCompile("day$"), regexp.MustCompile("y$"), regexp.MustCompile("x$"), regexp.MustCompile("([^s])s?$")}
|
var pluralMapKeys = []*regexp.Regexp{regexp.MustCompile("ch$"), regexp.MustCompile("ss$"), regexp.MustCompile("sh$"), regexp.MustCompile("day$"), regexp.MustCompile("y$"), regexp.MustCompile("x$"), regexp.MustCompile("([^s])s?$")}
|
||||||
var pluralMapValues = []string{"ches", "sses", "shes", "days", "ies", "xes", "${1}s"}
|
var pluralMapValues = []string{"ches", "sses", "shes", "days", "ies", "xes", "${1}s"}
|
||||||
|
|
||||||
func (scope *Scope) GetModelStruct() *ModelStruct {
|
func (scope *Scope) GetModelStruct(noRelationship ...bool) *ModelStruct {
|
||||||
var modelStruct ModelStruct
|
var modelStruct ModelStruct
|
||||||
|
|
||||||
reflectValue := reflect.Indirect(reflect.ValueOf(scope.Value))
|
reflectValue := reflect.Indirect(reflect.ValueOf(scope.Value))
|
||||||
@ -210,9 +210,9 @@ func (scope *Scope) GetModelStruct() *ModelStruct {
|
|||||||
field.IsNormal = true
|
field.IsNormal = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if !field.IsNormal {
|
if !field.IsNormal && len(noRelationship) == 0 {
|
||||||
gormSettings := parseTagSetting(field.Tag.Get("gorm"))
|
gormSettings := parseTagSetting(field.Tag.Get("gorm"))
|
||||||
toModelStruct := scope.New(reflect.New(fieldStruct.Type).Interface()).GetModelStruct()
|
toModelStruct := scope.New(reflect.New(fieldStruct.Type).Interface()).GetModelStruct(true)
|
||||||
getForeignField := func(column string, fields []*StructField) *StructField {
|
getForeignField := func(column string, fields []*StructField) *StructField {
|
||||||
for _, field := range fields {
|
for _, field := range fields {
|
||||||
if field.Name == column || field.DBName == ToDBName(column) {
|
if field.Name == column || field.DBName == ToDBName(column) {
|
||||||
@ -327,7 +327,7 @@ func (scope *Scope) GetModelStruct() *ModelStruct {
|
|||||||
modelStruct.StructFields = append(modelStruct.StructFields, field)
|
modelStruct.StructFields = append(modelStruct.StructFields, field)
|
||||||
}
|
}
|
||||||
|
|
||||||
if scope.db != nil {
|
if scope.db != nil && len(noRelationship) == 0 {
|
||||||
scope.db.parent.ModelStructs[scopeType] = &modelStruct
|
scope.db.parent.ModelStructs[scopeType] = &modelStruct
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,7 +160,7 @@ type Comment struct {
|
|||||||
Id int64
|
Id int64
|
||||||
PostId int64
|
PostId int64
|
||||||
Content string
|
Content string
|
||||||
// Post Post
|
Post Post
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scanner
|
// Scanner
|
||||||
|
Loading…
x
Reference in New Issue
Block a user