代码如下:
package main
import (
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/mssql"
_ "github.com/jinzhu/gorm/dialects/mysql"
_ "github.com/jinzhu/gorm/dialects/postgres"
_ "github.com/jinzhu/gorm/dialects/sqlite"
)
var db *gorm.DB
func init() {
var err error
db, err = gorm.Open("mysql", "gorm:gorm@tcp(localhost:9910)/gorm?charset=utf8&parseTime=True")
if err != nil {
panic(err)
}
db.LogMode(true)
}
type Res {
Id int `gorm:"column:id"`
age int `gorm:"column:age"`
}
func main() {
var result []Res
db.Table("A").Select("A.id,A.age").Joins("left join B on A.id=B.id").
Where("A.age=28").
Not("B.id", []{2,3,4,5}).
Scan(&result)
fmt.Printf("%v", result)
}
但是最后sql 日志输出的是 select A.id,A.age from A left join B on A.id=B.id where a.age=28 and A.B.id not in(2,3,4,5)
B.id 变成了 A.B.id not in 了。。
这里改如何处理? 怎么指定Not() 操作的是哪个表的字段?