Refactor merge where exprs

This commit is contained in:
Jinzhu 2020-06-08 09:10:27 +08:00
parent 72d0fa6196
commit 8f8d549ca3
3 changed files with 6 additions and 5 deletions

View File

@ -40,9 +40,10 @@ func (where Where) Build(builder Builder) {
// MergeClause merge where clauses // MergeClause merge where clauses
func (where Where) MergeClause(clause *Clause) { func (where Where) MergeClause(clause *Clause) {
if w, ok := clause.Expression.(Where); ok { if w, ok := clause.Expression.(Where); ok {
copiedExpressions := make([]Expression, len(w.Exprs)) exprs := make([]Expression, len(w.Exprs)+len(where.Exprs))
copy(copiedExpressions, w.Exprs) copy(exprs, w.Exprs)
where.Exprs = append(copiedExpressions, where.Exprs...) copy(exprs[len(w.Exprs):], where.Exprs)
where.Exprs = exprs
} }
clause.Expression = where clause.Expression = where

View File

@ -34,4 +34,3 @@ func TestWhereCloneCorruption(t *testing.T) {
}) })
} }
} }

View File

@ -14,6 +14,7 @@ type Hamster struct {
} }
func TestNamedPolymorphic(t *testing.T) { func TestNamedPolymorphic(t *testing.T) {
DB.Migrator().DropTable(&Hamster{})
DB.AutoMigrate(&Hamster{}) DB.AutoMigrate(&Hamster{})
hamster := Hamster{Name: "Mr. Hammond", PreferredToy: Toy{Name: "bike"}, OtherToy: Toy{Name: "treadmill"}} hamster := Hamster{Name: "Mr. Hammond", PreferredToy: Toy{Name: "bike"}, OtherToy: Toy{Name: "treadmill"}}