Posted By

rduv on 09/29/06


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

webstic


associations are not enough


 / Published in: Ruby
 

  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  

You need to login to post a comment.