我有两个同名的表,我正在做一个连接
Visits::Appointment
name:string
id:integer
...
Places::Seatables
name:string
appointment_id:integer
id:integer
....
我想做一个外连接并获得所有字段。当我执行以下操作时,我只从可座位表中获得名称和id。
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.*')
如何获得两个字段而不是只有一个
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')
现在你可以通过
访问它们appointment = appointments.first
appointment.seatable_name
appointment.seatable_id