Fix errors being inaccessible due to errors being set on different *DB instance than what is returned.

This commit is contained in:
Jay Taylor 2015-06-23 15:27:21 -07:00
parent dbedca4e5f
commit c2c1dd1fc8
1 changed files with 17 additions and 11 deletions

28
main.go
View File

@ -396,28 +396,33 @@ func (s *DB) AutoMigrate(values ...interface{}) *DB {
} }
func (s *DB) ModifyColumn(column string, typ string) *DB { func (s *DB) ModifyColumn(column string, typ string) *DB {
s.clone().NewScope(s.Value).modifyColumn(column, typ) scope := s.clone().NewScope(s.Value)
return s scope.modifyColumn(column, typ)
return scope.db
} }
func (s *DB) DropColumn(column string) *DB { func (s *DB) DropColumn(column string) *DB {
s.clone().NewScope(s.Value).dropColumn(column) scope := s.clone().NewScope(s.Value)
return s scope.dropColumn(column)
return scope.db
} }
func (s *DB) AddIndex(indexName string, column ...string) *DB { func (s *DB) AddIndex(indexName string, column ...string) *DB {
s.clone().NewScope(s.Value).addIndex(false, indexName, column...) scope := s.clone().NewScope(s.Value)
return s scope.addIndex(false, indexName, column...)
return scope.db
} }
func (s *DB) AddUniqueIndex(indexName string, column ...string) *DB { func (s *DB) AddUniqueIndex(indexName string, column ...string) *DB {
s.clone().NewScope(s.Value).addIndex(true, indexName, column...) scope := s.clone().NewScope(s.Value)
return s scope.addIndex(true, indexName, column...)
return scope.db
} }
func (s *DB) RemoveIndex(indexName string) *DB { func (s *DB) RemoveIndex(indexName string) *DB {
s.clone().NewScope(s.Value).removeIndex(indexName) scope := s.clone().NewScope(s.Value)
return s scope.removeIndex(indexName)
return scope.db
} }
/* /*
@ -427,7 +432,8 @@ Example:
db.Model(&User{}).AddForeignKey("city_id", "cities(id)", "RESTRICT", "RESTRICT") db.Model(&User{}).AddForeignKey("city_id", "cities(id)", "RESTRICT", "RESTRICT")
*/ */
func (s *DB) AddForeignKey(field string, dest string, onDelete string, onUpdate string) *DB { func (s *DB) AddForeignKey(field string, dest string, onDelete string, onUpdate string) *DB {
s.clone().NewScope(s.Value).addForeignKey(field, dest, onDelete, onUpdate) scope := s.clone().NewScope(s.Value)
scope.addForeignKey(field, dest, onDelete, onUpdate)
return s return s
} }