Rails 3 find all associated records has_many :through

Posted by Sergey on Stack Overflow See other posts from Stack Overflow or by Sergey
Published on 2010-05-09T18:48:55Z Indexed on 2010/05/09 18:58 UTC
Read the original article Hit count: 236

Filed under:
|
|
|
|

I would like to list all posts that are connected with some specific category.

I have:

class Post < ActiveRecord::Base
  has_many :category_posts
  has_many :categories, :through => :category_posts
end

class Category < ActiveRecord::Base
  has_many :category_posts
  has_many :posts, :through => :category_posts
end

class CategoryPost < ActiveRecord::Base
  belongs_to :category
  belongs_to :post
end

And I wanna do something like this

Post.where(["category.id = ?", params[:category_id]])

It indeed is very simple task, but I don't know what I should be looking for (keywords).

It's the same problem like this, but in rails.

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby