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
|
// 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
|
||||||
|
|
|
@ -34,4 +34,3 @@ func TestWhereCloneCorruption(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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"}}
|
||||||
|
|
Loading…
Reference in New Issue