开发者

How can i filter a resource and it's nested resources in rails 3?

I have categories and each category has resources that belong to them. I want to use a scope on all categories an开发者_运维知识库d a different scope on their resources.

This is an example of what i am trying to do:

categories = Category.find_all_by_name('something').resources.find_all_by_resource_type_id(3)


your post ain't exactly crystal clear

my guess is that you probably want the categories that have "something" name, and their resources eager-loaded. for that use this:

Category.where(:name => 'something').includes(:resources)

or, if you want to specify what resources you want for those "something" categories, you can use this:

Category.includes(:resources).where(:name => 'something', :resources => {:resource_type_id => 3})

more info about active record querying, here

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜