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,, as role from A INNER JOIN B on A.foreignKey1 = INNER JOIN C on A.foreignKey2 = INNER JOIN D on = D.foreignKey INNER JOIN E on = 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!