Sha256: 77ceb77c5135dbc4beca7e2d641d1a556920b59ec1d7f45ba9f1b10a6eb4da94

Contents?: true

Size: 1.02 KB

Versions: 5

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true
# A set of Participants.
class Group < ActiveRecord::Base
  belongs_to :arm
  belongs_to :creator, class_name: "User"

  has_many :memberships, dependent: :restrict_with_exception
  has_many :participants, through: :memberships
  has_many :active_memberships,
           -> { active },
           class_name: "Membership",
           foreign_key: :group_id,
           dependent: :destroy,
           inverse_of: :active_group
  has_many :tasks, dependent: :destroy
  has_many :active_participants, through: :active_memberships

  validates :arm_id, presence: true
  validates :title, presence: true, length: { maximum: 50 }, uniqueness: true

  delegate :count, to: :memberships, prefix: true

  def learning_tasks
    tasks
      .joins(:bit_core_content_module)
      .where(
        BitCore::ContentModule.arel_table[:type]
        .eq("ContentModules::LessonModule")
      )
  end

  def non_moderator_memberships
    memberships.joins(:participant)
               .merge(Participant.not_moderator)
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
think_feel_do_engine-3.22.9 app/models/group.rb
think_feel_do_engine-3.22.8 app/models/group.rb
think_feel_do_engine-3.22.7 app/models/group.rb
think_feel_do_engine-3.22.6 app/models/group.rb
think_feel_do_engine-3.22.5 app/models/group.rb