Wouldn't it be something like the following:

suess_chapter_three = Chapter.find(:all, :include=>:book, :conditions => 
['books.auther like "suess" and chapters.chapter = 3'])

Simon

On Fri, 13 Mar 2009 09:24:29 +0900, Avi Ir <[email protected]> 
wrote:

>
> Hello,
>
> I am looking for a better way to do the following (my code examples are
> crappy pseudocode):
>
> I have two associated models, Book and Chapter, where book has_many
> chapters.  I want to first select several books, for example,
>
> books_by_dr_seuss = Book.find(:all, :conditions => {:author => "Seuss"
> })
>
> Then, I want to select all the "Chapter 3"'s from this result, i.e.
> Chapter 3 of Cat in the Hat, Chapter 3 of Fox in Socks, etc.
>
> I want to do something like:
>
> chapter_threes = Chapter.find(:all, :include=>[:book], :conditions =>
> {chapter.book in books_by_dr_seuss } )
>
> How would I do this without resorting to something like "select * from
> chapters where chapter.book_id=1 or chapter.book_id=2, etc"?
>
> Thanks for your help.
> A





--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to