Re: Searching through HABTM

Jables
Fri, 30 May 2008 03:21:17 -0000

Thanks for the info guys,
  Genre.find_by_name("genre").stories is close to what I want.  Let me
make it a bit more complex though now:
I want to be able to take those stories of a certain genre and order
them by rating or post date, and filter them by another factor which
is category (and maybe even another parameter).  So Story also HABTM
categories and has a rating/post_date parameter.  As the number of
stories in a genre is going to grow largely it seems wildly
inefficient to take the array of all the stories then increment though
each one check to see if it is in the right category and sorting by
date.  What I really need is something like:

Story.find_by_genre_and_category_and_anotherthing("genre",
"category",
"anotherthing", :conditions =>  "post_date <
somedate", :order =>
"rating DESC")

Anybody have any ideas?

Thanks,
JB