首页 > 解决方案 > go-pg 如何覆盖链接表

问题描述

具有以下规格的三个表:

type Devices struct {
   ID         int
   Name  string
}

type Features struct {
   ID        int
   Name string
}

我创建了一个由以下结构指定的链接表:

type DevicesFeatures struct {
    DeviceID   int
    Device *Devices
    FeatureID int
    Feature *Features
}

我想选择所有设备及其功能(如果有)。像下面这样的查询对我有用:

select A.name, C.name from devices as A left join devices_fearures as B on A.id =B.device_id left join features as C on C.id = B.feature_id 

标签: gogo-pg

解决方案


推荐阅读