I have two models in my Rails app: Listing and ListingPhoto. I want to set some kind of scope on my model that removes Listings that have no nested ListingPhotos. These are being pulled in from an external API, so I have no easy way to control these saving.
Listing looks like this:
class Listing < ActiveRecord::Base
acts_as_taggable_on :listing_types
has_many :listing_photos
accepts_nested_attributes_for :listing_photos, allow_destroy: true
private
end
ListingPhoto looks like this:
class ListingPhoto < ActiveRecord::Base
belongs_to :listing
validates :listing, presence: true
mount_uploader :photo, PhotoUploader
end
What would I need to add to my Listing model to stop listings with empty photo sets showing up?