TIP: Use Markdown or, <pre> for multi line code blocks / <code> for inline code.
These forums are read-only and for archival purposes only!
Please join our new forums at discourse.kohanaframework.org
ORM and multiple joins using has_many_through
  • Is it possible to generate a query with ORM that does multiple joins of tables that have a "has_many_through" relationship? I have database with three tables: projects, counties, and [subject] areas, plus two pivot tables (counties_projects and area_projects). If I want to generate a query along the lines of :

    SELECT p.PROJECT_NAME, a.AREA_NAME FROM projects p JOIN counties_projects cp ON (cp.project_id = p.id) JOIN counties c on (c.id=cp.county_id) JOIN areas_projects ap on (ap.project_id = p.id) join areas a on (a.id=ap.area_id) where (c.id = '13') ORDER BY PROJECT_NAME ASC

    Can this be done using ORM, or does this need to be done via the query builder ? (I may need to use queries with even more joins than this example)