Your Question
I have a piece of code, looking that this like
fieldDb := db.Model(&MyModel{}).Select("first_field, second_field, ...")
for _, id := range ids {
var data Date
err := fieldDb.Where("id = ?", id).First(&data)
if err != nil {
return
}
......
}
And where in range becomes where and id where and id.... . i wish where is not and
i find gorm document only session NewDb function, not alone like function NewWhere .
i don't want to delete anything other than where
finally, I don't want to create a new db in for
Thanks for answering my question
Comment From: 0x2d3c
I don't know why your code was written like that
i think this way will be better
var res []Data
if err := db.Model(&MyModel{}).Select("first_field, second_field, ...").Where("id IN (?)",ids).Find(&res).Err(); err!=nil {
return err
}
Comment From: Gpihuier
This is just pseudo code. I just want to know whether there is a function of clearing conditions separately, or whether there is a support plan in the future
Comment From: 0x2d3c
i don't know if there is a way for you, but DB struct has Statement field, you need self definition impl feature
Gpihuier @.***> 于2022年12月19日周一 14:23写道:
This is just pseudo code. I just want to know whether there is a function of clearing conditions separately, or whether there is a support plan in the future
— Reply to this email directly, view it on GitHub https://github.com/go-gorm/gorm/issues/5926#issuecomment-1357159492, or unsubscribe https://github.com/notifications/unsubscribe-auth/AE4FJH2THMWBNJTKHXLQ3RTWN75PZANCNFSM6AAAAAATAX3FRA . You are receiving this because you commented.Message ID: @.***>
Comment From: Gpihuier
thank you. I'm ready to close issues
Comment From: Gpihuier
I tried to write some code, although I know it is not strict but it fulfilled my original requirements The code looks like this
package db
import (
"gorm.io/gorm"
"gorm.io/gorm/clause"
)
db.Statement.RemoveClause(clause.Where{}, clause.OrderBy{})
// write in gorm.statement.go
// RemoveClause remove clause
func (stmt *Statement) RemoveClause(clauses ...clause.Interface) {
for _, v := range clauses {
name := v.Name()
stmt.Clauses[name] = clause.Clause{}
}
}
Comment From: a631807682
https://gorm.io/docs/method_chaining.html#New-Session-Method