On 4 Nov 2008, at 16:38, Andrew Porter wrote:
>
> Tom Ha wrote:
>> Hi there,
>>
>> In the model situation "Book :has_many Stories", I would like to do
>> something like this:
>>
>> Book.find(:all, :conditions => { book.story.id => @story_ids })
>>
>> ...which of course doesn't work with "book.story.id =>..."
>> (-> "undefined local variable or method 'book'")
>>
>> What's the correct query syntax for such a case (where I query across
>> the 2 tables 'Books' and 'Stories')?
>
> The magic you are looking for is :include
Actually it's :joins. That's something of a misuse of :include.
The keys in the hash should be qualified column names (eg :conditions
=> {'stories.id' => @story_ids}).
:joins can either be an sql fragment or an association name (or array
or hash of those)
Fred
>
>
>
> >
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---