mirror of https://github.com/go-gorm/gorm.git
Fix all tests for GetModelStruct
This commit is contained in:
parent
4bc06a21c1
commit
8a0c77e5fc
|
@ -254,6 +254,21 @@ func (scope *Scope) GetModelStruct() *ModelStruct {
|
||||||
} else {
|
} else {
|
||||||
relationship.Kind = "has_many"
|
relationship.Kind = "has_many"
|
||||||
|
|
||||||
|
if polymorphic := field.TagSettings["POLYMORPHIC"]; polymorphic != "" {
|
||||||
|
if polymorphicField := getForeignField(polymorphic+"ID", toScope.GetStructFields()); polymorphicField != nil {
|
||||||
|
if polymorphicType := getForeignField(polymorphic+"Type", toScope.GetStructFields()); polymorphicType != nil {
|
||||||
|
relationship.ForeignFieldNames = []string{polymorphicField.Name}
|
||||||
|
relationship.ForeignDBNames = []string{polymorphicField.DBName}
|
||||||
|
relationship.AssociationForeignFieldNames = []string{scope.PrimaryField().Name}
|
||||||
|
relationship.AssociationForeignDBNames = []string{scope.PrimaryField().DBName}
|
||||||
|
relationship.PolymorphicType = polymorphicType.Name
|
||||||
|
relationship.PolymorphicDBName = polymorphicType.DBName
|
||||||
|
polymorphicType.IsForeignKey = true
|
||||||
|
polymorphicField.IsForeignKey = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// if no foreign keys
|
// if no foreign keys
|
||||||
if len(foreignKeys) == 0 {
|
if len(foreignKeys) == 0 {
|
||||||
if len(associationForeignKeys) == 0 {
|
if len(associationForeignKeys) == 0 {
|
||||||
|
@ -311,6 +326,21 @@ func (scope *Scope) GetModelStruct() *ModelStruct {
|
||||||
tagAssociationForeignKeys = strings.Split(field.TagSettings["ASSOCIATIONFOREIGNKEY"], ";")
|
tagAssociationForeignKeys = strings.Split(field.TagSettings["ASSOCIATIONFOREIGNKEY"], ";")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if polymorphic := field.TagSettings["POLYMORPHIC"]; polymorphic != "" {
|
||||||
|
if polymorphicField := getForeignField(polymorphic+"ID", toScope.GetStructFields()); polymorphicField != nil {
|
||||||
|
if polymorphicType := getForeignField(polymorphic+"Type", toScope.GetStructFields()); polymorphicType != nil {
|
||||||
|
relationship.ForeignFieldNames = []string{polymorphicField.Name}
|
||||||
|
relationship.ForeignDBNames = []string{polymorphicField.DBName}
|
||||||
|
relationship.AssociationForeignFieldNames = []string{scope.PrimaryField().Name}
|
||||||
|
relationship.AssociationForeignDBNames = []string{scope.PrimaryField().DBName}
|
||||||
|
relationship.PolymorphicType = polymorphicType.Name
|
||||||
|
relationship.PolymorphicDBName = polymorphicType.DBName
|
||||||
|
polymorphicType.IsForeignKey = true
|
||||||
|
polymorphicField.IsForeignKey = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Has One
|
// Has One
|
||||||
{
|
{
|
||||||
var foreignKeys = tagForeignKeys
|
var foreignKeys = tagForeignKeys
|
||||||
|
|
Loading…
Reference in New Issue