【发布时间】:2015-02-26 20:57:14
【问题描述】:
我有以下关系:
# Project
has_many :teammates
has_many :users, through: :teammates
# User
has_many :teammates
has_many :projects, through: :teammates
# Teammate
belongs_to :user
belongs_to :project
teammate 表有一个“角色”字段,说明用户在项目中的角色。 这就是我在数据库中保存具有该角色的队友的方式:
project.teammates.create(:user => current_user, :role => 10)
所以这是有效的。现在我想做的是从特定项目中获取所有用户,所有用户都有一个角色字段,告诉他们在该项目中的角色。
这可能吗?我读过一些关于向用户模型添加attribute_accessible 的帖子,但这不再出现在rails 4 中。
【问题讨论】:
标签: ruby-on-rails attributes has-many-through