开发者

Finding records when using has_many through associations

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 c开发者_如何转开发an do this?


Try:

worker.projects.all(:conditions => {:status_id => 'active'})


worker.projects.all(:conditions => {:status_id => 'active'})

will work. (answer edited after the comment)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜