associations are not enough


/ Published in: Ruby
Save to your folder(s)



Copy this code and paste it in your HTML
  1. def self.find_with_all_actors(*actors)
  2. return [] if actors.empty?
  3. actors = actors.flatten
  4. find(:all, :readonly => false,
  5. :joins => "INNER JOIN appearances a ON movies.id = a.movie_id",
  6. :conditions => "a.actor_id IN (#{actors.map(&:id).join(', ')})",
  7. :group => "movies.id HAVING COUNT(movies.id) = #{actors.size}")
  8. end

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.