我不知道我在做什麼錯在這裏,但我想爲我有一個模型創建範圍,但我希望它評估相關模型的計數...就像說:Rails,範圍問題
class Thing < ActiveRecord::Base
has_many :photos
scope :with_images, self.photo.count > 0
end
class Photo < ActiveRecord::Base
belongs_to :thing
end
那麼我應該有一個範圍,其將工作像
Thing.where('some conditions').with_images
我得到的照片NoMethodError
,爲什麼不這樣可作爲一個關係?我不想用它作爲一種方法。