This should do the trick:
from_table = Arel::Table.new(:from)
to_table = Arel::Table.new(:to)
rates_table = Arel::Table.new(:rates)
query = rates_table.
join(from_table).on(rates_table[:from_id].eq(from_table[:id])).
join(to_table).on(rates_table[:to_id].eq(to_table[:id])).
project(rates_table[Arel.star]).
with([
Arel::Nodes::As.new(from_table, Arel::Nodes::SqlLiteral.new("select * query")),
Arel::Nodes::As.new(to_table, Arel::Nodes::SqlLiteral.new("another select *")),
Arel::Nodes::As.new(rates_table, Arel::Nodes::SqlLiteral.new("yet another select *")),
])
puts query.to_sql
You should replace the Arel::Nodes::SqlLiteral.new("another select *")
expressions with an actual Arel query. To get the Arel query from an ActiveRecord relation, you can call .ast
on it. Example: User.where(active: true).ast
.