我有一个多对多的关联,例如
class User < ActiveRecord::Base
has_many :working_groups
has_many :groups, :through => :working_groups
class Group < ActiveRecord::Base
has_many :working_groups
has_many :users, :through => :working_groups
class WorkingGroup < ActiveRecord::Base
belongs_to :user
belongs_to :group
Working_Groups 关联有一些关于每个关系的附加信息(例如成员的顺序和类型):
create_table "working_groups", :force => true do |t|
t.integer "group_id"
t.integer "user_id"
t.integer "position"
t.string "role"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
在用户视图中,我试图显示用户所属的所有组的列表及其成员资格类型(存储在联接表中)。我发现完成这项工作的唯一方法是这样的,它看起来非常丑陋,而且不是有史以来最有效的事情......
名称 角色有一个更好的方法吗?一定会有更好的办法...