次の 2 つのモデルがあるとします。
class Wheel
belongs_to :car
def self.flat
where(flat: true)
end
と
class Car
has_many :wheels
def flats
self.wheels.flat
end
def has_flats?
flats.count > 0
end
タイヤがパンクしているすべての車のクエリが必要です。なぜこれが車のモデルで機能しないのだろうか?:
def self.with_flats
where(:has_flats?)
end
また
def self.with_flats
where(:has_flats? == true)
end
これは正しいレコードを返しません。何か案は?