在ruby on rails上的join语句抛出错误MySQL ::错误:未知列

时间:2017-02-14 09:59:30

标签: mysql ruby-on-rails

parts = Participation.joins(:booking).where(bookings: { date_of_booking: Date.yesterday }, payment_status: 2)

我有上面的join语句,即使列date_of_booking存在,mysql也会抛出错误

  

ActiveRecord :: StatementInvalid:Mysql2 ::错误:未知列' bookings.date_of_booking'在' where子句':SELECT ad_trek_participant。* FROM ad_trek_participant INNER JOIN ad_trek_booking ON ad_trek_bookingId = ad_trek_participantBooking_Id WHERE bookingsdate_of_booking =' 2017-02-13'和ad_trek_participantpayment_status = 2

对此有任何帮助。

1 个答案:

答案 0 :(得分:0)

Participation.joins(:booking).where(payment_status: 2).where("ad_trek_booking.date_of_booking > ?",Date.today - 6.days)

表格名称更改为ad_trek_booking wherejoins(:booking)和{{1}}给定型号名称,它有效。