Rails Join -如何获得相同名称的字段



我有两个同名的表,我正在做一个连接

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

相关内容

  • 没有找到相关文章

最新更新