适用于范围内用户的HABTM

时间:2019-02-27 12:20:30

标签: ruby-on-rails activerecord associations

如何在有作用域的用户(assigned_user)之间实现HABTM关系 和评估模型,我有usersassessments模型

user.rb

  devise :database_authenticatable,
         :recoverable, :rememberable, :validatable

  has_many :assessments
end

assessment.rb

class Assessment < ApplicationRecord
  belongs_to :user
  has_and_belongs_to_many :assigned_user, class_name: 'User'

  scope :assigned_user, -> { where('user.role == proctor') }
end

如何在范围assigned_userassessments之间创建联接表

0 个答案:

没有答案