Find across has many association

I have an article and category.

An article belongs to a category.
A category has many articles.

I want to find all articles in the “programming” category.

I have tried:
prog_articles = Article.find(:all, :conditions => [“category = ?”,
“programming”])

I know this is wrong because the error message reports an unknown column
on the article table (makes sense because this is a join).

What I do not understand is how to represent the join accurately?

I have scanned AWDR and not found an answer yet.

Thank you for any help.

John

I added an :include => :category clause to the above statement and it
seems to work now.

On Feb 5, 5:44 pm, John H. [email protected]
wrote:


A category has many articles.

I want to find all articles in the “programming” category.

category.find_by_name(“programming”).articles

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs