Refactor model struct

This commit is contained in:
Jinzhu 2015-02-16 16:35:26 +08:00
parent 1726cebc2e
commit 3a73206010
6 changed files with 132 additions and 167 deletions

View File

@ -32,8 +32,8 @@ func SaveBeforeAssociations(scope *Scope) {
} }
scope.Err(newDB.Save(value.Addr().Interface()).Error) scope.Err(newDB.Save(value.Addr().Interface()).Error)
if relationship.ForeignKey != "" { if relationship.ForeignFieldName != "" {
scope.SetColumn(relationship.ForeignKey, newDB.NewScope(value.Addr().Interface()).PrimaryKeyValue()) scope.SetColumn(relationship.ForeignFieldName, newDB.NewScope(value.Addr().Interface()).PrimaryKeyValue())
} }
if relationship.ForeignType != "" { if relationship.ForeignType != "" {
scope.Err(fmt.Errorf("gorm does not support polymorphic belongs_to associations")) scope.Err(fmt.Errorf("gorm does not support polymorphic belongs_to associations"))
@ -58,8 +58,8 @@ func SaveAfterAssociations(scope *Scope) {
newDB := scope.NewDB() newDB := scope.NewDB()
elem := value.Index(i).Addr().Interface() elem := value.Index(i).Addr().Interface()
if relationship.JoinTable == "" && relationship.ForeignKey != "" { if relationship.JoinTable == "" && relationship.ForeignFieldName != "" {
newDB.NewScope(elem).SetColumn(relationship.ForeignKey, scope.PrimaryKeyValue()) newDB.NewScope(elem).SetColumn(relationship.ForeignFieldName, scope.PrimaryKeyValue())
} }
if relationship.ForeignType != "" { if relationship.ForeignType != "" {
newDB.NewScope(elem).SetColumn(relationship.ForeignType, scope.TableName()) newDB.NewScope(elem).SetColumn(relationship.ForeignType, scope.TableName())
@ -74,9 +74,9 @@ func SaveAfterAssociations(scope *Scope) {
newScope := scope.New(elem) newScope := scope.New(elem)
joinTable := relationship.JoinTable joinTable := relationship.JoinTable
foreignKey := ToSnake(relationship.ForeignKey) foreignKey := ToSnake(relationship.ForeignFieldName)
foreignValue := fmt.Sprintf("%v", scope.PrimaryKeyValue()) foreignValue := fmt.Sprintf("%v", scope.PrimaryKeyValue())
associationForeignKey := ToSnake(relationship.AssociationForeignKey) associationForeignKey := ToSnake(relationship.AssociationForeignFieldName)
associationForeignValue := fmt.Sprintf("%v", newScope.PrimaryKeyValue()) associationForeignValue := fmt.Sprintf("%v", newScope.PrimaryKeyValue())
newScope.Raw(fmt.Sprintf( newScope.Raw(fmt.Sprintf(
@ -97,8 +97,8 @@ func SaveAfterAssociations(scope *Scope) {
default: default:
newDB := scope.NewDB() newDB := scope.NewDB()
if value.CanAddr() { if value.CanAddr() {
if relationship.ForeignKey != "" { if relationship.ForeignFieldName != "" {
newDB.NewScope(value.Addr().Interface()).SetColumn(relationship.ForeignKey, scope.PrimaryKeyValue()) newDB.NewScope(value.Addr().Interface()).SetColumn(relationship.ForeignFieldName, scope.PrimaryKeyValue())
} }
if relationship.ForeignType != "" { if relationship.ForeignType != "" {
newDB.NewScope(value.Addr().Interface()).SetColumn(relationship.ForeignType, scope.TableName()) newDB.NewScope(value.Addr().Interface()).SetColumn(relationship.ForeignType, scope.TableName())
@ -112,8 +112,8 @@ func SaveAfterAssociations(scope *Scope) {
} }
elem := destValue.Addr().Interface() elem := destValue.Addr().Interface()
if relationship.ForeignKey != "" { if relationship.ForeignFieldName != "" {
newDB.NewScope(elem).SetColumn(relationship.ForeignKey, scope.PrimaryKeyValue()) newDB.NewScope(elem).SetColumn(relationship.ForeignFieldName, scope.PrimaryKeyValue())
} }
if relationship.ForeignType != "" { if relationship.ForeignType != "" {
newDB.NewScope(value.Addr().Interface()).SetColumn(relationship.ForeignType, scope.TableName()) newDB.NewScope(value.Addr().Interface()).SetColumn(relationship.ForeignType, scope.TableName())

View File

@ -430,7 +430,7 @@ func (s *DB) Association(column string) *Association {
var field *Field var field *Field
var ok bool var ok bool
if field, ok = scope.FieldByName(column); ok { if field, ok = scope.FieldByName(column); ok {
if field.Relationship == nil || field.Relationship.ForeignKey == "" { if field.Relationship == nil || field.Relationship.ForeignFieldName == "" {
scope.Err(fmt.Errorf("invalid association %v for %v", column, scope.IndirectValue().Type())) scope.Err(fmt.Errorf("invalid association %v for %v", column, scope.IndirectValue().Type()))
} }
} else { } else {

View File

@ -2,9 +2,12 @@ package gorm
import ( import (
"database/sql" "database/sql"
"fmt"
"go/ast" "go/ast"
"reflect" "reflect"
"regexp"
"strconv" "strconv"
"strings"
"time" "time"
) )
@ -23,7 +26,10 @@ type StructField struct {
IsNormal bool IsNormal bool
IsIgnored bool IsIgnored bool
DefaultValue *string DefaultValue *string
GormSettings map[string]string
SqlSettings map[string]string
SqlTag string SqlTag string
Struct reflect.StructField
Relationship *Relationship Relationship *Relationship
} }
@ -37,14 +43,81 @@ type Relationship struct {
JoinTable string JoinTable string
} }
func (scope *Scope) GetStructFields() (fields []*StructField) { func (scope *Scope) GenerateSqlTag(field *StructField) {
var sqlType string
reflectValue := reflect.New(field.Struct.Type)
if value, ok := field.SqlSettings["TYPE"]; ok {
sqlType = value
}
additionalType := field.SqlSettings["NOT NULL"] + " " + field.SqlSettings["UNIQUE"]
if value, ok := field.SqlSettings["DEFAULT"]; ok {
additionalType = additionalType + "DEFAULT " + value
}
if field.IsScanner {
var getScannerValue func(reflect.Value)
getScannerValue = func(reflectValue reflect.Value) {
if _, isScanner := reflect.New(reflectValue.Type()).Interface().(sql.Scanner); isScanner {
getScannerValue(reflectValue.Field(0))
}
}
getScannerValue(reflectValue.Field(0))
}
if sqlType == "" {
var size = 255
if value, ok := field.SqlSettings["SIZE"]; ok {
size, _ = strconv.Atoi(value)
}
if field.IsPrimaryKey {
sqlType = scope.Dialect().PrimaryKeyTag(reflectValue, size)
} else {
sqlType = scope.Dialect().SqlTag(reflectValue, size)
}
}
if strings.TrimSpace(additionalType) == "" {
field.SqlTag = sqlType
} else {
field.SqlTag = fmt.Sprintf("%v %v", sqlType, additionalType)
}
}
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"}
func (scope *Scope) GetModelStruct() *ModelStruct {
var modelStruct ModelStruct
reflectValue := reflect.Indirect(reflect.ValueOf(scope.Value)) reflectValue := reflect.Indirect(reflect.ValueOf(scope.Value))
if reflectValue.Kind() == reflect.Slice { if reflectValue.Kind() == reflect.Slice {
reflectValue = reflect.Indirect(reflect.New(reflectValue.Elem().Type())) reflectValue = reflect.Indirect(reflect.New(reflectValue.Elem().Type()))
} }
scopeTyp := reflectValue.Type() scopeTyp := reflectValue.Type()
hasPrimaryKey := false
// Set tablename
if fm := reflect.New(scopeTyp).MethodByName("TableName"); fm.IsValid() {
if results := fm.Call([]reflect.Value{}); len(results) > 0 {
if name, ok := results[0].Interface().(string); ok {
modelStruct.TableName = name
}
}
} else {
modelStruct.TableName = ToSnake(scopeTyp.Name())
if scope.db == nil || !scope.db.parent.singularTable {
for index, reg := range pluralMapKeys {
if reg.MatchString(modelStruct.TableName) {
modelStruct.TableName = reg.ReplaceAllString(modelStruct.TableName, pluralMapValues[index])
}
}
}
}
// Set fields
for i := 0; i < scopeTyp.NumField(); i++ { for i := 0; i < scopeTyp.NumField(); i++ {
fieldStruct := scopeTyp.Field(i) fieldStruct := scopeTyp.Field(i)
if !ast.IsExported(fieldStruct.Name) { if !ast.IsExported(fieldStruct.Name) {
@ -52,21 +125,22 @@ func (scope *Scope) GetStructFields() (fields []*StructField) {
} }
var field *StructField var field *StructField
field.Struct = fieldStruct
if fieldStruct.Tag.Get("sql") == "-" { if fieldStruct.Tag.Get("sql") == "-" {
field.IsIgnored = true field.IsIgnored = true
} else { } else {
sqlSettings := parseTagSetting(fieldStruct.Tag.Get("sql")) field.SqlSettings = parseTagSetting(fieldStruct.Tag.Get("sql"))
settings := parseTagSetting(fieldStruct.Tag.Get("gorm")) field.GormSettings = parseTagSetting(fieldStruct.Tag.Get("gorm"))
if _, ok := settings["PRIMARY_KEY"]; ok { if _, ok := field.GormSettings["PRIMARY_KEY"]; ok {
field.IsPrimaryKey = true field.IsPrimaryKey = true
hasPrimaryKey = true modelStruct.PrimaryKeyField = field
} }
if value, ok := sqlSettings["DEFAULT"]; ok { if value, ok := field.SqlSettings["DEFAULT"]; ok {
field.DefaultValue = &value field.DefaultValue = &value
} }
if value, ok := settings["COLUMN"]; ok { if value, ok := field.GormSettings["COLUMN"]; ok {
field.DBName = value field.DBName = value
} else { } else {
field.DBName = ToSnake(fieldStruct.Name) field.DBName = ToSnake(fieldStruct.Name)
@ -85,11 +159,11 @@ func (scope *Scope) GetStructFields() (fields []*StructField) {
field.IsTime, field.IsNormal = true, true field.IsTime, field.IsNormal = true, true
} }
many2many := settings["MANY2MANY"] many2many := field.GormSettings["MANY2MANY"]
foreignKey := SnakeToUpperCamel(settings["FOREIGNKEY"]) foreignKey := SnakeToUpperCamel(field.GormSettings["FOREIGNKEY"])
foreignType := SnakeToUpperCamel(settings["FOREIGNTYPE"]) foreignType := SnakeToUpperCamel(field.GormSettings["FOREIGNTYPE"])
associationForeignKey := SnakeToUpperCamel(settings["ASSOCIATIONFOREIGNKEY"]) associationForeignKey := SnakeToUpperCamel(field.GormSettings["ASSOCIATIONFOREIGNKEY"])
if polymorphic := SnakeToUpperCamel(settings["POLYMORPHIC"]); polymorphic != "" { if polymorphic := SnakeToUpperCamel(field.GormSettings["POLYMORPHIC"]); polymorphic != "" {
foreignKey = polymorphic + "Id" foreignKey = polymorphic + "Id"
foreignType = polymorphic + "Type" foreignType = polymorphic + "Type"
} }
@ -119,20 +193,20 @@ func (scope *Scope) GetStructFields() (fields []*StructField) {
foreignKey = "" foreignKey = ""
} }
field.Relationship = &relationship{ field.Relationship = &Relationship{
JoinTable: many2many, JoinTable: many2many,
ForeignKey: foreignKey, ForeignType: foreignType,
ForeignType: foreignType, ForeignFieldName: foreignKey,
AssociationForeignKey: associationForeignKey, AssociationForeignFieldName: associationForeignKey,
Kind: kind, Kind: kind,
} }
} else { } else {
field.IsNormal = true field.IsNormal = true
} }
case reflect.Struct: case reflect.Struct:
if _, ok := settings["EMBEDDED"]; ok || fieldStruct.Anonymous { if _, ok := field.GormSettings["EMBEDDED"]; ok || fieldStruct.Anonymous {
for _, field := range scope.New(reflect.New(indirectType).Interface()).GetStructFields() { for _, field := range scope.New(reflect.New(indirectType).Interface()).GetStructFields() {
fields = append(fields, field) modelStruct.StructFields = append(modelStruct.StructFields, field)
} }
break break
} else { } else {
@ -154,7 +228,7 @@ func (scope *Scope) GetStructFields() (fields []*StructField) {
kind = "has_one" kind = "has_one"
} }
field.Relationship = &relationship{ForeignKey: foreignKey, ForeignType: foreignType, Kind: kind} field.Relationship = &Relationship{ForeignFieldName: foreignKey, ForeignType: foreignType, Kind: kind}
} }
default: default:
@ -162,64 +236,21 @@ func (scope *Scope) GetStructFields() (fields []*StructField) {
} }
} }
} }
fields = append(fields, field) modelStruct.StructFields = append(modelStruct.StructFields, field)
} }
if !hasPrimaryKey { for _, field := range modelStruct.StructFields {
for _, field := range fields { if modelStruct.PrimaryKeyField == nil && field.DBName == "id" {
if field.DBName == "id" { field.IsPrimaryKey = true
field.IsPrimaryKey = true modelStruct.PrimaryKeyField = field
}
} }
scope.GenerateSqlTag(field)
} }
for _, field := range fields { return &modelStruct
var sqlType string }
size := 255
sqlTag := field.Tag.Get("sql") func (scope *Scope) GetStructFields() (fields []*StructField) {
sqlSetting = parseTagSetting(sqlTag) return scope.GetModelStruct().StructFields
if value, ok := sqlSetting["SIZE"]; ok {
if i, err := strconv.Atoi(value); err == nil {
size = i
} else {
size = 0
}
}
if value, ok := sqlSetting["TYPE"]; ok {
typ = value
}
additionalType := sqlSetting["NOT NULL"] + " " + sqlSetting["UNIQUE"]
if value, ok := sqlSetting["DEFAULT"]; ok {
additionalType = additionalType + "DEFAULT " + value
}
if field.IsScanner {
var getScannerValue func(reflect.Value)
getScannerValue = func(reflectValue reflect.Value) {
if _, isScanner := reflect.New(reflectValue.Type()).Interface().(sql.Scanner); isScanner {
getScannerValue(reflectValue.Field(0))
}
}
getScannerValue(reflectValue.Field(0))
}
if field.IsNormal {
typ + " " + additionalType
} else if !field.IsTime {
return typ + " " + additionalType
}
if len(typ) == 0 {
if field.IsPrimaryKey {
typ = scope.Dialect().PrimaryKeyTag(reflectValue, size)
} else {
typ = scope.Dialect().SqlTag(reflectValue, size)
}
}
return typ + " " + additionalType
}
return
} }

View File

@ -46,14 +46,14 @@ func Preload(scope *Scope) {
switch relation.Kind { switch relation.Kind {
case "has_one": case "has_one":
condition := fmt.Sprintf("%v IN (?)", scope.Quote(relation.ForeignDBName())) condition := fmt.Sprintf("%v IN (?)", scope.Quote(relation.ForeignDBName))
scope.NewDB().Where(condition, scope.getColumnAsArray(primaryName)).Find(results, conditions...) scope.NewDB().Where(condition, scope.getColumnAsArray(primaryName)).Find(results, conditions...)
resultValues := reflect.Indirect(reflect.ValueOf(results)) resultValues := reflect.Indirect(reflect.ValueOf(results))
for i := 0; i < resultValues.Len(); i++ { for i := 0; i < resultValues.Len(); i++ {
result := resultValues.Index(i) result := resultValues.Index(i)
if isSlice { if isSlice {
value := getFieldValue(result, relation.ForeignKey) value := getFieldValue(result, relation.ForeignFieldName)
objects := scope.IndirectValue() objects := scope.IndirectValue()
for j := 0; j < objects.Len(); j++ { for j := 0; j < objects.Len(); j++ {
if equalAsString(getFieldValue(objects.Index(j), primaryName), value) { if equalAsString(getFieldValue(objects.Index(j), primaryName), value) {
@ -66,13 +66,13 @@ func Preload(scope *Scope) {
} }
} }
case "has_many": case "has_many":
condition := fmt.Sprintf("%v IN (?)", scope.Quote(relation.ForeignDBName())) condition := fmt.Sprintf("%v IN (?)", scope.Quote(relation.ForeignDBName))
scope.NewDB().Where(condition, scope.getColumnAsArray(primaryName)).Find(results, conditions...) scope.NewDB().Where(condition, scope.getColumnAsArray(primaryName)).Find(results, conditions...)
resultValues := reflect.Indirect(reflect.ValueOf(results)) resultValues := reflect.Indirect(reflect.ValueOf(results))
if isSlice { if isSlice {
for i := 0; i < resultValues.Len(); i++ { for i := 0; i < resultValues.Len(); i++ {
result := resultValues.Index(i) result := resultValues.Index(i)
value := getFieldValue(result, relation.ForeignKey) value := getFieldValue(result, relation.ForeignFieldName)
objects := scope.IndirectValue() objects := scope.IndirectValue()
for j := 0; j < objects.Len(); j++ { for j := 0; j < objects.Len(); j++ {
object := reflect.Indirect(objects.Index(j)) object := reflect.Indirect(objects.Index(j))
@ -87,7 +87,7 @@ func Preload(scope *Scope) {
scope.SetColumn(field, resultValues) scope.SetColumn(field, resultValues)
} }
case "belongs_to": case "belongs_to":
scope.NewDB().Where(scope.getColumnAsArray(relation.ForeignKey)).Find(results, conditions...) scope.NewDB().Where(scope.getColumnAsArray(relation.ForeignFieldName)).Find(results, conditions...)
resultValues := reflect.Indirect(reflect.ValueOf(results)) resultValues := reflect.Indirect(reflect.ValueOf(results))
for i := 0; i < resultValues.Len(); i++ { for i := 0; i < resultValues.Len(); i++ {
result := resultValues.Index(i) result := resultValues.Index(i)
@ -96,7 +96,7 @@ func Preload(scope *Scope) {
objects := scope.IndirectValue() objects := scope.IndirectValue()
for j := 0; j < objects.Len(); j++ { for j := 0; j < objects.Len(); j++ {
object := reflect.Indirect(objects.Index(j)) object := reflect.Indirect(objects.Index(j))
if equalAsString(getFieldValue(object, relation.ForeignKey), value) { if equalAsString(getFieldValue(object, relation.ForeignFieldName), value) {
object.FieldByName(field.Name).Set(result) object.FieldByName(field.Name).Set(result)
} }
} }

View File

@ -7,7 +7,6 @@ import (
"time" "time"
"reflect" "reflect"
"regexp"
) )
type Scope struct { type Scope struct {
@ -227,8 +226,6 @@ func (scope *Scope) AddToVars(value interface{}) string {
} }
// TableName get table name // TableName get table name
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"}
func (scope *Scope) TableName() string { func (scope *Scope) TableName() string {
if scope.Search != nil && len(scope.Search.TableName) > 0 { if scope.Search != nil && len(scope.Search.TableName) > 0 {

View File

@ -364,69 +364,6 @@ func (scope *Scope) updatedAttrsWithValues(values map[string]interface{}, ignore
return return
} }
func (scope *Scope) sqlTagForField(field *Field) (typ string) {
if scope.db == nil {
return ""
}
var size = 255
fieldTag := field.Tag.Get(scope.db.parent.tagIdentifier)
var setting = parseTagSetting(fieldTag)
if value, ok := setting["SIZE"]; ok {
if i, err := strconv.Atoi(value); err == nil {
size = i
} else {
size = 0
}
}
if value, ok := setting["TYPE"]; ok {
typ = value
}
additionalType := setting["NOT NULL"] + " " + setting["UNIQUE"]
if value, ok := setting["DEFAULT"]; ok {
additionalType = additionalType + "DEFAULT " + value
}
value := field.Field.Interface()
reflectValue := field.Field
if reflectValue.Kind() == reflect.Ptr {
reflectValue = reflect.New(reflectValue.Type().Elem()).Elem()
}
switch reflectValue.Kind() {
case reflect.Slice:
if _, ok := value.([]byte); !ok {
return typ + " " + additionalType
}
case reflect.Struct:
if field.IsScanner {
var getScannerValue func(reflect.Value)
getScannerValue = func(value reflect.Value) {
reflectValue = value
if _, isScanner := reflect.New(reflectValue.Type()).Interface().(sql.Scanner); isScanner {
getScannerValue(reflectValue.Field(0))
}
}
getScannerValue(reflectValue.Field(0))
} else if !field.IsTime {
return typ + " " + additionalType
}
}
if len(typ) == 0 {
if field.IsPrimaryKey {
typ = scope.Dialect().PrimaryKeyTag(reflectValue, size)
} else {
typ = scope.Dialect().SqlTag(reflectValue, size)
}
}
return typ + " " + additionalType
}
func (scope *Scope) row() *sql.Row { func (scope *Scope) row() *sql.Row {
defer scope.Trace(NowFunc()) defer scope.Trace(NowFunc())
scope.prepareQuerySql() scope.prepareQuerySql()
@ -495,7 +432,7 @@ func (scope *Scope) related(value interface{}, foreignKeys ...string) *Scope {
foreignKey = keys[1] foreignKey = keys[1]
} }
var relationship *relationship var relationship *Relationship
var field *Field var field *Field
var scopeHasField bool var scopeHasField bool
if field, scopeHasField = scope.FieldByName(foreignKey); scopeHasField { if field, scopeHasField = scope.FieldByName(foreignKey); scopeHasField {
@ -504,8 +441,8 @@ func (scope *Scope) related(value interface{}, foreignKeys ...string) *Scope {
if scopeType == "" || scopeType == fromScopeType { if scopeType == "" || scopeType == fromScopeType {
if scopeHasField { if scopeHasField {
if relationship != nil && relationship.ForeignKey != "" { if relationship != nil && relationship.ForeignFieldName != "" {
foreignKey = relationship.ForeignKey foreignKey = relationship.ForeignFieldName
} }
if relationship != nil && relationship.Kind == "many_to_many" { if relationship != nil && relationship.Kind == "many_to_many" {
@ -516,10 +453,10 @@ func (scope *Scope) related(value interface{}, foreignKeys ...string) *Scope {
"INNER JOIN %v ON %v.%v = %v.%v", "INNER JOIN %v ON %v.%v = %v.%v",
scope.Quote(relationship.JoinTable), scope.Quote(relationship.JoinTable),
scope.Quote(relationship.JoinTable), scope.Quote(relationship.JoinTable),
scope.Quote(ToSnake(relationship.AssociationForeignKey)), scope.Quote(ToSnake(relationship.AssociationForeignFieldName)),
toScope.QuotedTableName(), toScope.QuotedTableName(),
scope.Quote(toScope.PrimaryKey())) scope.Quote(toScope.PrimaryKey()))
whereSql := fmt.Sprintf("%v.%v = ?", scope.Quote(relationship.JoinTable), scope.Quote(ToSnake(relationship.ForeignKey))) whereSql := fmt.Sprintf("%v.%v = ?", scope.Quote(relationship.JoinTable), scope.Quote(ToSnake(relationship.ForeignFieldName)))
toScope.db.Joins(joinSql).Where(whereSql, scope.PrimaryKeyValue()).Find(value) toScope.db.Joins(joinSql).Where(whereSql, scope.PrimaryKeyValue()).Find(value)
return scope return scope
} }
@ -567,8 +504,8 @@ func (scope *Scope) createJoinTable(field *Field) {
newScope.Raw(fmt.Sprintf("CREATE TABLE %v (%v)", newScope.Raw(fmt.Sprintf("CREATE TABLE %v (%v)",
field.Relationship.JoinTable, field.Relationship.JoinTable,
strings.Join([]string{ strings.Join([]string{
scope.Quote(ToSnake(field.Relationship.ForeignKey)) + " " + primaryKeySqlType, scope.Quote(ToSnake(field.Relationship.ForeignFieldName)) + " " + primaryKeySqlType,
scope.Quote(ToSnake(field.Relationship.AssociationForeignKey)) + " " + primaryKeySqlType}, ",")), scope.Quote(ToSnake(field.Relationship.AssociationForeignFieldName)) + " " + primaryKeySqlType}, ",")),
).Exec() ).Exec()
scope.Err(newScope.db.Error) scope.Err(newScope.db.Error)
} }