开发者

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

开发者 https://www.devze.com 2023-02-19 03:13 出处:网络
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.

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

精彩评论

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

关注公众号