我对 GORM 和 MySQL 有疑问。我有这个结构:
type Users struct {
ID string
Balance Balances
Model
}
type Model struct {
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt *time.Time
}
type Balances struct {
UID string `gorm:"foreignkey:ID;unique_index"`
USD int
}
我想选择余额中 USD 字段大于 0 的用户。我该怎么做?
无论如何,db.Find(&users)获取所有用户,但不是他们的余额。实际上,执行的查询是:SELECT * FROM users WHERE users.deleted_at IS NULL
绝地无双
相关分类