Use the same database for Related

This commit is contained in:
Jinzhu 2014-03-07 19:08:33 +08:00
parent 0156c26cfa
commit 24d527670b
1 changed files with 1 additions and 0 deletions

View File

@ -396,6 +396,7 @@ func (scope *Scope) typeName() string {
func (scope *Scope) related(value interface{}, foreignKeys ...string) *Scope { func (scope *Scope) related(value interface{}, foreignKeys ...string) *Scope {
toScope := scope.New(value) toScope := scope.New(value)
toScope.db = scope.db
for _, foreignKey := range append(foreignKeys, toScope.typeName()+"Id", scope.typeName()+"Id") { for _, foreignKey := range append(foreignKeys, toScope.typeName()+"Id", scope.typeName()+"Id") {
if foreignValue, ok := scope.FieldByName(foreignKey); ok { if foreignValue, ok := scope.FieldByName(foreignKey); ok {