论坛首页 Ruby版 rails

一个类能不能有两个一样的has_many子类集合,就像一个聊天室有主持人和所有人,但他们都是User

浏览 281 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
最后更新时间:2008-05-29 关键字: has_many through hasmanythroughsourceassociationnotfounderr
class Chatroom < ActiveRecord::Base
  has_many :replies
  has_many :discussants 
  has_many :users,
           :through => :discussants
  has_many :comperes,  
           :through => :discussants,  
           :class_name => "User",  
           :conditions => ['role = 6']
end

视图里调用users是正常的,但调用comperes出错,提示
ActiveRecord::HasManyThroughSourceAssociationNotFoundError in Chatrooms#index
Showing chatrooms/index.html.erb where line #11 raised:

Could not find the source association(s) :compere or :comperes in model Discussant.  Try 'has_many :comperes, :through => :discussants, :source => <name>'.  Is it one of :chatroom or :user?

一个开源项目里用同样的示例运行也有问题。
rails2.0 ruby1.8 Mongrel 1.1.2
   
最后更新时间:2008-05-29
你按他的提示做试试。
has_many :comperes,
:through => :discussants,
:source => :user,
:conditions => ['role = 6']
   
0 请登录后投票
最后更新时间:2008-05-29
奇怪原来试过不行,现在又试了一遍,又可以了。:)
   
0 请登录后投票
论坛首页 Ruby版 rails

跳转论坛:
JavaEye推荐