I feel like this is a simple problem I’m having due to my misunderstanding of the new ActiveRecord query interface, but take this example:
>> Category.first.recipes
=> [ ... ] # array of recipes
However:
>> Category.where(:id => 1).recipes
=> NoMethodError: undefined method `recipes' for #<ActiveRecord::Relation:0x000001033dc9e0>
What’s going on here? why does my where method return an ActiveRecord::Relation object? how can I retrieve the objects from the query here?
This is actually intentional.
The objects are only retrieved when special methods like first, each etc are called. This is called lazy loading which is a great when you want to cache your views. Read more about why here.