views:

21

answers:

2

I have two models, Worker and Project, and they are connected with has_many through association.

I manage to find all the projects which are related to a specific worker by writing the following code:

worker=Worker.find_by_id("some_id") 
worker.projects 

but I want the projects that I get to be only active projects (in the project model I have a status field)

I tried to do something like

worker.projects(:status_id=>'active')

but it didn’t work for me.

Can somebody tell me how I can do this?

+1  A: 

Try:

worker.projects.all(:conditions => {:status_id => 'active'})
Matchu
+1  A: 
worker.projects.all(:conditions => {:status_id => 'active'})

will work. (answer edited after the comment)

piemesons
They do, in fact, behave differently, though. `#find` throws an exception on failure, whereas `#find_by_id` returns nil on failure.
Matchu
Oh thanks Matchu.. editing my answer...
piemesons