I have this snippet of ActiveRecord:
scope = Listing.where(Listing.arel_table[:price].gt(6_000_000))
The resulting sql:
SELECT listings.* FROM listings where listings.price > 6000000
I would like to add a CTE that would result in this sql:
WITH lookup AS (
SELECT the_geom FROM lookup WHERE slug = 'foo-bar'
)
SELECT * from listings, lookup
WHERE listings.price > 6000000
AND ST_within(listings.the_geom, lookup.the_geom)
I would like to express this sql inclusive of the CTE using Arel and ActiveRecord.
I would also like to use the scope variable as a starting point.
from
. ie. justSELECT * FROM listings WHERE
notSELECT * FROM listings, lookup WHERE
– Simmer