Question

I have two tables with same name and am doing a join

Visits::Appointment
    name:string
    id:integer
    ...


Places::Seatables
    name:string
    appointment_id:integer
    id:integer
    ....

I want to do a outer join and get all the fields. I am getting only the name and id from the seatable table when I do the following.

  Visits::Appointment.joins("LEFT OUTER JOIN places_seatables ON  places_seatables.appointment_id=visits_appointments.id").where('checkout is null and "isActive" is true and noshow is false').select(visits_appointments.*,places_seatables.*')

How can I get both the fields instead of just one

Was it helpful?

Solution

appointments = Visits::Appointment
               .joins("LEFT OUTER JOIN places_seatables ON  places_seatables.appointment_id=visits_appointments.id")
               .where('checkout is null and "isActive" is true and noshow is false')
               .select(visits_appointments.*,places_seatables.name as seatable_name, places_seatables.id as seatable_id')

Now you can access them as

appointment = appointments.first
appointment.seatable_name
appointment.seatable_id
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top