My question is whether the rails helper methods for handling
associations can
be nested (see examples below). I suspect not as currently I’m
getting “unknown method” if I try and use two associations in one call.
The essence of the code is
class User << ActiveRecord::Base
has_many :items
class Items << ActiveRecord::Base
has_many :reservations
belongs_to :user
class Reservations << ActiveRecord::Base
belongs_to :item
I’ve specified foreign_key fields etc.
What works:
user.items.size
item.reservations.size
What doesn’t work (and my question for the group)
user.items.reservations.size
In other words returning the number of reservations made against all
items
that are owned by a user.
In this case I will get the error "undefined method `reservations’ for
Item:Class
Is this supposed to work? If not how should I work around it?
thanks
Chris