Rails 4 Inner Join On Same Table

Viewed 893

In a Rails 4 app I have the following associations :

User has_many :bookings
Booking belongs_to :client, class_name: "User"

I am trying to make a JOIN through tables to grab the Booking AND the CLIENT:

User.joins("INNER JOIN bookings on users.id = bookings.user_id").joins("INNER JOIN users on bookings.client_id = users.id") 

Which returns:

PG::DuplicateAlias: ERROR:  table name "users" specified more than once

Is there a solution to fetch the 2 associations?

1 Answers
Related