HABTM & find_all_by

Hello!

I’m a little new to rails and have a strange problem i’m trying to
decipher.

I have a Project model and Category model, connected together by a HABTM
(with a categorys_projects join table)

Rails is doing everything as it should, apart from the find.

Am I wrong to think that I should be able to go:-

projects = Project.find_all_by_category(some_id)

As the only way I can return projects of a certain category right now is
using
a join like so :

projects = Project.find(:all, joins => :categories, :conditions =>
{:categories => { :id => params[:category] } })

Where:-

class Project < ActiveRecord::Base
has_and_belongs_to_many :categories
end

class Category < ActiveRecord::Base
has_and_belongs_to_many :projects
end

Bit confused!

Any help would be great

Thanks!
K

Hi

how about this?

category = Category.find some_id
projects = category.projects

projects = Project.find_all_by_category(some_id) will not work,
because find_all_by_… methods work only for existing columns in
table

Hope it helps )

Bob wrote:

Hi

how about this?

category = Category.find some_id
projects = category.projects

projects = Project.find_all_by_category(some_id) will not work,
because find_all_by_… methods work only for existing columns in
table

Hope it helps )

I think I understand what you’re saying!

Thanks a bunch!