Apply a query mod to a join? #376
-
I am doing something like this (this is a reduced query from the original, but it should have everything necessary to ask/answer the question): query := models.Devices.Query(
ctx, r.ReadDB(),
sm.Distinct(),
sm.InnerJoin(models.DeviceLocations.Name()).On(models.DeviceColumns.ID.EQ(models.DeviceLocationColumns.DeviceID)),
sm.Limit(filters.Limit()),
sm.Offset(filters.Offset()),
models.ThenLoadDeviceDeviceLocations(
sm.OrderBy(models.DeviceLocationColumns.RegisteredAt).Desc(),
),
)
// Sort Query Mods
for _, sortMod := range common.SortColumns(models.DeviceColumns.Serial, models.DeviceColumns.Name, models.DeviceColumns.ObservedAt).Using(filters) {
query.Apply(sortMod)
}
// Filter Query Mods
for _, filterMod := range common.FilterColumns(models.DeviceColumns.Serial, models.DeviceColumns.Name, models.DeviceColumns.ObservedAt).Using(filters) {
query.Apply(filterMod)
} The This works great for filtering on the main table, but I am wondering if there is a way to apply filter mods to also filter by device locations in the join? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Sorry for the late reply... Can you share an example of the query you're trying to build? |
Beta Was this translation helpful? Give feedback.
Sorry for the late reply...
Can you share an example of the query you're trying to build?