I have two models, Place and Region. This seems like a good place to
have a composite primary key, but seems that Rails doesnt support it.
That would be fine, except the data I’m working with and will be
importing has the following columns, with the levels representing a
level of region (such as state/province, county, district, etc.)
Region: country_id, level1, level2, name
Place: id, name, … level1, level2 …
This raw SQL works for displaying the place along with the name of
it’s region. How do I achieve the same result through the ActiveRecord
Place.find(:all, :include => :region)?
SELECT places.id, places.name, places.country_id, countries.name,
INNER JOIN regions ON places.country_id = regions.country_id
AND places.admin1 = regions.level1
AND places.admin2 = regions.level2
LEFT JOIN countries ON places.country_id = countries.id