Добрый день.
Застрял на реализации в рельсах сложного запроса, вида:
SELECT *
FROM
(SELECT
directory_records.id AS did,
organisations.title AS org
FROM "directory_records"
LEFT OUTER JOIN organisations
ON organisations.id = directory_records.organisation_id
LEFT OUTER JOIN directory_values
ON directory_values.directory_record_id = directory_records.id
WHERE "directory_records"."directory_id" = 20
AND (organisations.title ILIKE '%текст%' OR directory_values.value ILIKE '%текст2%')
AND directory_values.field = 'vendor'
ORDER BY directory_values.value DESC
LIMIT 10
OFFSET 0
) AS q1
LEFT JOIN (SELECT
directory_records.id AS did2,
directory_values.field,
directory_values.value,
directory_values.value_float,
directory_values.value_int,
directory_values.value_time
FROM "directory_values"
LEFT OUTER JOIN directory_records
ON directory_records.id = directory_values.directory_record_id
) AS q2
ON did = q2.did2
Как его реализовать в ORM RoR?