forked from mirror/gorm
Support create/drop multiple tables
This commit is contained in:
parent
9303e070c8
commit
1d5f5f43f3
|
@ -6,13 +6,8 @@ import (
|
|||
)
|
||||
|
||||
func TestHasOneAndHasManyAssociation(t *testing.T) {
|
||||
DB.DropTable(Category{})
|
||||
DB.DropTable(Post{})
|
||||
DB.DropTable(Comment{})
|
||||
|
||||
DB.CreateTable(Category{})
|
||||
DB.CreateTable(Post{})
|
||||
DB.CreateTable(Comment{})
|
||||
DB.DropTable(Category{}, Post{}, Comment{})
|
||||
DB.CreateTable(Category{}, Post{}, Comment{})
|
||||
|
||||
post := Post{
|
||||
Title: "post 1",
|
||||
|
|
24
main.go
24
main.go
|
@ -373,16 +373,28 @@ func (s *DB) RecordNotFound() bool {
|
|||
}
|
||||
|
||||
// Migrations
|
||||
func (s *DB) CreateTable(value interface{}) *DB {
|
||||
return s.clone().NewScope(value).createTable().db
|
||||
func (s *DB) CreateTable(values ...interface{}) *DB {
|
||||
db := s.clone()
|
||||
for _, value := range values {
|
||||
db = db.NewScope(value).createTable().db
|
||||
}
|
||||
return db
|
||||
}
|
||||
|
||||
func (s *DB) DropTable(value interface{}) *DB {
|
||||
return s.clone().NewScope(value).dropTable().db
|
||||
func (s *DB) DropTable(values ...interface{}) *DB {
|
||||
db := s.clone()
|
||||
for _, value := range values {
|
||||
db = db.NewScope(value).dropTable().db
|
||||
}
|
||||
return db
|
||||
}
|
||||
|
||||
func (s *DB) DropTableIfExists(value interface{}) *DB {
|
||||
return s.clone().NewScope(value).dropTableIfExists().db
|
||||
func (s *DB) DropTableIfExists(values ...interface{}) *DB {
|
||||
db := s.clone()
|
||||
for _, value := range values {
|
||||
db = db.NewScope(value).dropTableIfExists().db
|
||||
}
|
||||
return db
|
||||
}
|
||||
|
||||
func (s *DB) HasTable(value interface{}) bool {
|
||||
|
|
Loading…
Reference in New Issue