ruby - Hide record in Rails model if nested_attributes are empty -


I have two models in the Railway app: listing and ListingPhoto . I want to create some kind of scope for my model which removes listing s which is not nested ListingPhoto s is being pulled from the external API, so my There is no easy way to control these savings.

Listing looks like this:

  entering the class & lt;    looks like this:  
  code> class listing photo & lt; ActiveRecord :: Base is_to: Listing Valid: Listing, Attendance: Right Mount_uploader: Photo, Photo Uploader and   

What should I add to my listing model to stop Show listing with empty picture set?

You can add static method to the listing model:

  def Self.with_photos includes (: listing_photos) .where.not (: listing_photos = & gt; {: listing_id = & gt; blue}} end   

and then simply call easily :

  listing. With_photos    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -