1
has_many :squads, :dependent => :destroy
has_many :users, :through => :squads, :source => :squad_users
隊
has_many :squad_users, :dependent => :destroy
has_many :users, :through => :squad_users
用戶
has_many :squad_users
has_many :squads, :through => :squad_users
has_many :events, :through => :squads
SquadUser
belongs_to :squad
belongs_to :user
我創建在用戶模式中的一些named_scopes如下:
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"]
嘗試這樣:
<%= @event.users.large.size %>
,我也得到:
undefined method `large' for SquadUser(squad_id: integer, user_id: integer):Class
我的理解......沒有對SquadUser模型中沒有 「大」 的屬性。
我不明白的是如何在我想要得到什麼?一個簡單的方法來計算我需要訂購的每個事件每個尺寸的襯衫數量: -/