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
精彩评论