现在有俩个表
type A struct {
...
}
type B struct {
...
AID string `gorm:"column:a_id;not null;"`
...
}
B 表中有 A 的 ID 。
现在实现了以下 SQL 。
select a.*,
(
select count(*)
from b
where b.a_id = a.id
) as b_count
from a
Gorm
db = db.Select(`a.*, (
select count(*)
from b
where b.a_id = a.id
) as b_count`)
但 A 表中没有 b_count 字段,所以关联不上。这个要怎么实现。
先谢谢各位好兄弟