Event
has_many :squads, :dependent => :destroy
has_many :users, :through => :squads, :source => :squad_users
Squad
has_many :squad_users, :dependent => :destroy
has_many :users, :through => :squad_users
User
has_many :squad_users
has_many :squads, :through => :squad_users
has_many :events, :through => :squads
SquadUser
belongs_to :squad
belongs_to :user
I created a few named_scopes in the User model as follows:
named_scope :xtralarge, :conditions => [ "shirt = ?", "XL"]
named_scope :large, :conditions => [ "shirt = ?", "L"]
named_scope :medium, :conditions => [ "shirt = ?", "M"]
named_scope :small, :conditions => [ "shirt = ?", "S"]
named_scope :xtrasmall, :conditions => [ "shirt = ?", "XS"]
Tried this:
<%= @event.users.large.size %>
and I get:
undefined method `large' for SquadUser(squad_id: integer, user_id: integer):Class
Which I understand...there is no "large" attribute on the SquadUser model.
What I don't understand is how to get at what I want...an easy way to count the number of each size shirt I need to order for each event :-/