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
。* FROMad_trek_participant
INNER JOINad_trek_booking
ONad_trek_booking
。Id
=ad_trek_participant
。Booking_Id
WHEREbookings
。date_of_booking
=' 2017-02-13'和ad_trek_participant
。payment_status
= 2
对此有任何帮助。
答案 0 :(得分:0)
Participation.joins(:booking).where(payment_status: 2).where("ad_trek_booking.date_of_booking > ?",Date.today - 6.days)
表格名称更改为ad_trek_booking
where
内joins(:booking)
和{{1}}给定型号名称,它有效。