GORM关联预紧力与主密钥ID int = 0无法使用
我下面有两个模型,
type Bot struct {
gorm.Model
Name string
ExchangeID uint
Exchange Exchange
}
type Exchange struct {
gorm.Model
Image string
Status string
}
这意味着一个机器人属于交换。
在我的数据库中,我在表“交换”中有一个行= 0的行,并且在表“ bots”中使用Exchange_id = 0的许多行。
问题在于,bot查询中的预加载不适用于具有Exchange_id = 0的行。它与具有Exchange_ID = 1,2,3的行效果很好...
有人遇到了这个问题吗?我认为这是具有特殊值0的GORS问题。我正在努力将bot和id中的ixchangid in in Id in in forkeends ne Exchange宣布为字符串,但它具有一些权衡。
I have two models below
type Bot struct {
gorm.Model
Name string
ExchangeID uint
Exchange Exchange
}
type Exchange struct {
gorm.Model
Image string
Status string
}
It means a Bot belongs to an Exchange.
In my database, i have a row with id = 0 in table "exchanges" and many rows with exchange_id = 0 in table "bots".
The issue is that Preload in Bot queries not work for rows that have exchange_id = 0. It works well with rows that have exchange_id = 1,2,3...
Has anyone met this issue? I think it's gorm issue with special value 0. I'm working around by declaring ExchangeId in Bot and Id in Exchange as string but it has some tradeoffs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论