rails active record - Advanced find
Posted
by par
on Stack Overflow
See other posts from Stack Overflow
or by par
Published on 2010-03-27T21:48:07Z
Indexed on
2010/03/27
21:53 UTC
Read the original article
Hit count: 137
ruby-on-rails
|activerecord
I have the following model setup - a User is interested in projects in many project Categories. Each Project has many categories. Like so:
class User
has_many :projects
has_and_belongs_to_many :project_categories
class Project
belongs_to :user
has_and_belongs_to_many :project_categories
class ProjectCategory
has_and_belongs_to_many :projects
has_and_belongs_to_many :users
Now, I'd like to do a find for projects with any of the catogories that a certain user are interested in, i.e. if a user is interested in project categories A,B,C then I'd like to find projects which are part of one or more of those project categories.
Anyone?
© Stack Overflow or respective owner