0

I am trying to figure out how to write the equivalent of this query in ActiveRecord:

SELECT id FROM projects, neighborhoods
WHERE ST_WITHIN(projects.lonlat, neighorhoods.the_geom);

I tried several approaches, including

Neighborhood.select(:id).from('projects').where("ST_WITHIN(projects.lonlat, neighorhoods.the_geom)")

But the resulting query always resolves to a single table. Can anyone help me out?

0

1 Answer 1

2

Make use of the amazing tool scuttle.io to covert SQL to Arel:

Neighborhood.select(:id).where(
  Arel::Nodes::NamedFunction.new(
    'ST_WITHIN', [
      Project.arel_table[:lonlat], Neighorhood.arel_table[:the_geom]
    ]
  )
)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.