I have the following models:
class Property < ActiveRecord::Base
has_many :photos
scope :no_photos, -> { where('properties.id NOT IN (SELECT DISTINCT(property_id) FROM photos)') }
end
class Photo < ActiveRecord::Base
belongs_to :property
end
I know that my scope is really inefficient. I need another way to get the properties that don´t have any photos associated to them.
Any help?