has_and_belongs_to_many の関係に問題があります。Doctors と PatientMeeting の 2 つのモデルがあります。
class Doctor < ActiveRecord::Base
has_and_belongs_to_many :patient_meetings
end
class PatientMeeting < ActiveRecord::Base
has_and_belongs_to_many :doctors
end
問題は、top50 でマークされた医師の患者会議を表示することです (top50 と呼ばれる bool 変数があります)。これらの医師の会議を降順で一覧表示し、今日と明日の日付のみを含めるクエリを作成する必要があります。これとバリエーションを試しましたが、うまくいきませんでした:
Doctor.joins(:patient_meetings).where(:top50 => true).where('patient_meetings.meeting_date' => Date.today.strftime("%Y-%m-%d")..Date.tomorrow.strftime("%Y-%m-%d")).order('patient_meetings.meeting_date DESC').limit(50)
ここで次に何をすべきかについてのアイデアがありません。どんな助けでも大歓迎です。