Append unused argument to gorm statement
This commit is contained in:
parent
ff26c82306
commit
4bb28e1217
@ -70,7 +70,7 @@ func (expr Expr) Build(builder Builder) {
|
||||
|
||||
if idx < len(expr.Vars) {
|
||||
for _, v := range expr.Vars[idx:] {
|
||||
builder.AddVar(builder, v)
|
||||
builder.AddVar(builder, sql.NamedArg{Value: v})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -284,6 +284,11 @@ func (stmt *Statement) BuildCondition(query interface{}, args ...interface{}) []
|
||||
return []clause.Expression{clause.NamedExpr{SQL: s, Vars: args}}
|
||||
}
|
||||
|
||||
if strings.Contains(strings.TrimSpace(s), " ") {
|
||||
// looks like a where condition
|
||||
return []clause.Expression{clause.Expr{SQL: s, Vars: args}}
|
||||
}
|
||||
|
||||
if len(args) == 1 {
|
||||
return []clause.Expression{clause.Eq{Column: s, Value: args[0]}}
|
||||
}
|
||||
|
@ -44,6 +44,10 @@ func TestPostgres(t *testing.T) {
|
||||
if err := DB.First(&result, "id = ?", harumph.ID).Error; err != nil || harumph.Name != "jinzhu" {
|
||||
t.Errorf("No error should happen, but got %v", err)
|
||||
}
|
||||
|
||||
if err := DB.Where("id = $1", harumph.ID).First(&Harumph{}).Error; err != nil || harumph.Name != "jinzhu" {
|
||||
t.Errorf("No error should happen, but got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
type Post struct {
|
||||
|
Loading…
x
Reference in New Issue
Block a user