views:

69

answers:

1

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 :-/

A: 

Your modeling associations are fundamentally incorrect. You're trying to do a has_many through THROUGH a has_many through. Rails does not support that by default. You can install this plugin and then maybe your associations would work. A serious suggestion would be to simplify your data model. Either case post your results after you're made the changes to the associations or installed the plugin.

script/plugin install git://github.com/JackDanger/nested_has_many_through.git

Shreyas Satish