Allow internal user to be part of an study group

This commit is contained in:
Sebastian Serth
2021-01-11 11:51:30 +01:00
parent c694c389ee
commit 423a5b08f9
3 changed files with 9 additions and 7 deletions

View File

@ -2,13 +2,15 @@
class StudyGroup < ApplicationRecord
has_many :study_group_memberships, dependent: :destroy
# Use `ExternalUser` as `source_type` for now.
# Using `User` will lead ActiveRecord to access the inexistent table `users`.
# Issue created: https://github.com/rails/rails/issues/34531
has_many :users, through: :study_group_memberships, source_type: 'ExternalUser'
has_many :external_users, through: :study_group_memberships, source_type: 'ExternalUser', source: :user
has_many :internal_users, through: :study_group_memberships, source_type: 'InternalUser', source: :user
has_many :submissions, dependent: :nullify
belongs_to :consumer
def users
external_users + internal_users
end
def to_s
if name.blank?
"StudyGroup " + id.to_s