mirror of https://github.com/go-gorm/gorm.git
Refactor merge where exprs
This commit is contained in:
parent
72d0fa6196
commit
8f8d549ca3
|
@ -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
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
|
||||
"gorm.io/gorm/clause"
|
||||
)
|
||||
|
||||
|
@ -34,4 +34,3 @@ func TestWhereCloneCorruption(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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"}}
|
||||
|
|
Loading…
Reference in New Issue