我有2个模型通过第三个模型连接多对多:
class User < ActiveRecord::Base
has_and_belongs_to_many :workspaces
end
class Workspace < ActiveRecord::Base
validates :title, presence: true
has_and_belongs_to_many :users
end
class UserWorkspace < ActiveRecord::Base
belongs_to :user
belongs_to :workspace
enum role: [:user, :admin]
end
不幸的是,我无法找到如何访问UserWorkspace的参数role
。例如,@workspace.user.last.role
不起作用。你能帮忙吗?