Railsでモデル間のクエリに問題があります。私はクラスMessage
そのbelongs_to: booking
があります。私の目標は、Booking
スコープに依存するMessage
にactive
スコープを追加することです。Railsでのモデル間のチェーンスコープ
class Booking < ActiveRecord::Base
has_one :event
has_many :messages
def self.active
includes(:event).
where('events.endtime >= ? AND status IS NOT ?'
Time.current.beginning_of_week,
statuses['canceled'])
end
end
class Message < ActiveRecord::Base
belongs_to :booking
belongs_to :person
self.active(person_id)
where(person_id: person_id).merge(Booking.active)
end
end
は、私は、関連するBooking
がactive
ある特定のPerson
に向けMessage
のを見つけたいです。したがって、Message.active
を作成する際にBooking.active
を使用したいと考えています。上記の実装でMessage.active(1)
を呼び出す
次のエラーが返されます。
Association named 'event' was not found on Message; perhaps you misspelled it?
は、私がMessage.active
の実装でBooking.active
を使用してMessage
sが返さ得ることができる方法はありますか?