精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2007-12-26
sun201200204 写道 EqBuyMaster中设belongs_to,并仿“Agile Rails”中第231页的做法,如下写: belongs_to :manager, :class_name => 'User', :foreign_key => 'manager' belongs_to :buyer, :class_name => 'User', :foreign_key => 'buyer' belongs_to :accepter, :class_name => 'User', :foreign_key => 'accepter' belongs_toperator , :class_name => 'User', :foreign_key => 'operator' 用的时候对应的用就OK了 其实belongs_to部分最正确的写法是: belongs_to :manager, :class_name => 'User', :foreign_key => 'manager_user_id' belongs_to :buyer, :class_name => 'User', :foreign_key => 'buyer_user_id' belongs_to :accepter, :class_name => 'User', :foreign_key => 'accepter_user_id' belongs_toperator , :class_name => 'User', :foreign_key => 'operator_user_id' eq_buy_masters表中的外键也就相应为manager_user_id,buyer_user_id,accepter_user_id,operator_user_id 这样的话,不论在list中以manager.real_name引用,还是在form中以 <%= collection_select :eq_buy_master, :manager_user_id, @all_users, :id, :real_name %>来用都正常。否则用collection_select是会出问题的。 |
|
返回顶楼 | |