On Sun, Feb 20, 2011 at 12:58 AM, Bharat Ruparel <[email protected]>wrote:

> A course has many lessons and a lesson has many topics.
> A topic can have a recipe or vice versa, a recipe has many topics
> (optional).
>
> I need to come up with the most efficient way of querying the database
> to find those topics belonging to a course (via lessons of course) which
> have a recipe (in other words recipe_id is not null for this topic
> record).
>
> What is most efficient, depends on whether you want to display only the
topics or you also want to display data from the course model, say course's
name etc.

As a hint, look for the difference between include and joins while doing
queries using associations.
Then, come up with your query, post it here and then ask if it is the best
way to do it, depending on your situation.

> Simple but challenging :)
>
> Thanks for your time.
>
> Bharat
>
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> 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.
>
>

-- 
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