Как написать такой подзапрос с помощью activerecord (ruby on rails):
SELECT id, unit_cdl_required, load_group_id
FROM loads lo
WHERE unit_cdl_required=FALSE AND
load_group_id NOT IN (
SELECT load_group_id
FROM loads
WHERE unit_cdl_required=TRUE
AND load_group_id=lo.load_group_id
);
Я пытался:
Load.where("unit_cdl_required=FALSE AND load_group_id NOT IN (SELECT load_group_id FROM loads WHERE unit_cdl_required=TRUE AND load_group_id=lo.load_group_id)")
но получил ERROR: missing FROM-clause entry for table "lo"
Моя схема такая: https://imgur.com/a/wr9Yzl2