How to perform a query that involves a table join of four or more tables with selected columns?

Hello, I have five tables: A, B, C, D, and E, and this query statement:

SELECT A.column2, B.column5, C.column3, D.column7, D.name, E.name as role from A INNER JOIN B on A.foreignKey1 = B.id INNER JOIN C on A.foreignKey2 = C.id INNER JOIN D on C.id = D.foreignKey INNER JOIN E on D.id = E.foreignKey

  • The foreignKey of each table is different. And table A has two foreign keys.
  • D and E both have a column called “name” but they are not the same.
  • I want to select some columns from EACH table as stated above.

What would be the Rails way to perform the above query statement ? Thanks so much!