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
func (where Where) MergeClause(clause *Clause) {
if w, ok := clause.Expression.(Where); ok {
copiedExpressions := make([]Expression, len(w.Exprs))
copy(copiedExpressions, w.Exprs)
where.Exprs = append(copiedExpressions, where.Exprs...)
exprs := make([]Expression, len(w.Exprs)+len(where.Exprs))
copy(exprs, w.Exprs)
copy(exprs[len(w.Exprs):], where.Exprs)
where.Exprs = exprs
}
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) {
DB.Migrator().DropTable(&Hamster{})
DB.AutoMigrate(&Hamster{})
hamster := Hamster{Name: "Mr. Hammond", PreferredToy: Toy{Name: "bike"}, OtherToy: Toy{Name: "treadmill"}}