mirror of https://github.com/go-gorm/gorm.git
Fix statement modifier support
This commit is contained in:
parent
1bbaa43951
commit
56bdded0f8
|
@ -27,6 +27,8 @@ func (db *DB) Clauses(conds ...clause.Expression) (tx *DB) {
|
||||||
for _, cond := range conds {
|
for _, cond := range conds {
|
||||||
if c, ok := cond.(clause.Interface); ok {
|
if c, ok := cond.(clause.Interface); ok {
|
||||||
tx.Statement.AddClause(c)
|
tx.Statement.AddClause(c)
|
||||||
|
} else if optimizer, ok := cond.(StatementModifier); ok {
|
||||||
|
optimizer.ModifyStatement(tx.Statement)
|
||||||
} else {
|
} else {
|
||||||
whereConds = append(whereConds, cond)
|
whereConds = append(whereConds, cond)
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ func (c Clause) Build(builder Builder) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.AfterNameExpression != nil {
|
if c.AfterNameExpression != nil {
|
||||||
c.BeforeExpression.Build(builder)
|
c.AfterNameExpression.Build(builder)
|
||||||
builder.WriteByte(' ')
|
builder.WriteByte(' ')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -202,12 +202,11 @@ func (stmt *Statement) AddClause(v clause.Interface) {
|
||||||
if optimizer, ok := v.(StatementModifier); ok {
|
if optimizer, ok := v.(StatementModifier); ok {
|
||||||
optimizer.ModifyStatement(stmt)
|
optimizer.ModifyStatement(stmt)
|
||||||
} else {
|
} else {
|
||||||
c, ok := stmt.Clauses[v.Name()]
|
name := v.Name()
|
||||||
if !ok {
|
c, _ := stmt.Clauses[name]
|
||||||
c.Name = v.Name()
|
c.Name = name
|
||||||
}
|
|
||||||
v.MergeClause(&c)
|
v.MergeClause(&c)
|
||||||
stmt.Clauses[v.Name()] = c
|
stmt.Clauses[name] = c
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue