From 2ee7de9fa5577a77ca28cef30af678aea50e91ba Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sat, 27 Jun 2015 12:36:38 +0800 Subject: [PATCH] bug fixed for sync2 --- session.go | 33 +++++++++++++++++++-------------- xorm.go | 2 +- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/session.go b/session.go index a1984805..79dbe3ae 100644 --- a/session.go +++ b/session.go @@ -3889,6 +3889,7 @@ func (s *Session) Sync2(beans ...interface{}) error { } var foundIndexNames = make(map[string]bool) + var addedNames = make(map[string]*core.Index) for name, index := range table.Indexes { var oriIndex *core.Index @@ -3912,20 +3913,7 @@ func (s *Session) Sync2(beans ...interface{}) error { } if oriIndex == nil { - if index.Type == core.UniqueType { - session := engine.NewSession() - session.Statement.RefTable = table - defer session.Close() - err = session.addUnique(table.Name, name) - } else if index.Type == core.IndexType { - session := engine.NewSession() - session.Statement.RefTable = table - defer session.Close() - err = session.addIndex(table.Name, name) - } - if err != nil { - return err - } + addedNames[name] = index } } @@ -3938,6 +3926,23 @@ func (s *Session) Sync2(beans ...interface{}) error { } } } + + for name, index := range addedNames { + if index.Type == core.UniqueType { + session := engine.NewSession() + session.Statement.RefTable = table + defer session.Close() + err = session.addUnique(table.Name, name) + } else if index.Type == core.IndexType { + session := engine.NewSession() + session.Statement.RefTable = table + defer session.Close() + err = session.addIndex(table.Name, name) + } + if err != nil { + return err + } + } } } diff --git a/xorm.go b/xorm.go index f5f8f2a7..8e630b9a 100644 --- a/xorm.go +++ b/xorm.go @@ -17,7 +17,7 @@ import ( ) const ( - Version string = "0.4.3.0526" + Version string = "0.4.3.0627" ) func regDrvsNDialects() bool {