Class: PartyTopic

Inherits:
ApplicationRecord show all
Includes:
Models::Auditable
Defined in:
app/models/party_topic.rb

Overview

== Schema Information

Table name: party_topics
Database name: primary

id :integer not null, primary key
comments :text
due_on :datetime
follow_up :boolean
instruction_type :enum
position :integer
state :string(20)
state_created_at :datetime
type :string(20)
created_at :datetime not null
updated_at :datetime not null
course_category_id :integer
course_enrollment_id :integer
course_exam_id :integer
creator_id :integer
party_id :integer not null
survey_enrollment_id :integer
topic_id :integer not null
trainer_party_id :integer
updater_id :integer

Indexes

index_party_topic_enrollment_and_exam (party_id,topic_id,course_enrollment_id,course_exam_id)
index_party_topics_on_topic_id (topic_id)
index_party_topics_on_type (type)
party_topics_trainer_party_id_idx (trainer_party_id)

Foreign Keys

fk_rails_... (party_id => parties.id) ON DELETE => cascade
fk_rails_... (topic_id => topics.id) ON DELETE => cascade
fk_rails_... (trainer_party_id => parties.id) ON DELETE => nullify

Constant Summary collapse

STATES =

States.

%i[assigned in_progress completed cancelled].freeze

Constants included from Models::Auditable

Models::Auditable::ALWAYS_IGNORED

Constants included from Schedulable

Schedulable::SIMPLE_FORM_OPTIONS

Belongs to collapse

Methods included from Models::Auditable

#creator, #updater

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Models::Auditable

#all_skipped_columns, #audit_reference_data, #should_not_save_version, #stamp_record

Methods inherited from ApplicationRecord

ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation

Methods included from Schedulable

config

Methods included from Models::AfterCommittable

#after_commit

Methods included from Models::EventPublishable

#publish_event

Class Method Details

.assignedActiveRecord::Relation<PartyTopic>

A relation of PartyTopics that are assigned. Active Record Scope

Returns:

See Also:



60
# File 'app/models/party_topic.rb', line 60

scope :assigned, -> { where(state: :assigned) }

.completedActiveRecord::Relation<PartyTopic>

A relation of PartyTopics that are completed. Active Record Scope

Returns:

See Also:



59
# File 'app/models/party_topic.rb', line 59

scope :completed, -> { where(state: :completed) }

.in_progressActiveRecord::Relation<PartyTopic>

A relation of PartyTopics that are in progress. Active Record Scope

Returns:

See Also:



58
# File 'app/models/party_topic.rb', line 58

scope :in_progress, -> { where(state: :in_progress) }

.ongoingActiveRecord::Relation<PartyTopic>

A relation of PartyTopics that are ongoing. Active Record Scope

Returns:

See Also:



61
# File 'app/models/party_topic.rb', line 61

scope :ongoing, -> { where(state: %i[in_progress assigned]) }

.sortedActiveRecord::Relation<PartyTopic>

A relation of PartyTopics that are sorted. Active Record Scope

Returns:

See Also:



62
63
64
65
# File 'app/models/party_topic.rb', line 62

scope :sorted, -> {
  joins(:topic)
    .order('topics.position, topics.title')
}

Instance Method Details

#completeObject



67
68
69
# File 'app/models/party_topic.rb', line 67

def complete
  update(state: 'completed')
end

#partyParty

Returns:

See Also:

Validations:



44
# File 'app/models/party_topic.rb', line 44

belongs_to :party, inverse_of: :party_topics, optional: true

#topicTopic

Returns:

See Also:

Validations:

  • Uniqueness ({ scope: %i[party_id type course_enrollment_id course_exam_id survey_enrollment_id] })


45
# File 'app/models/party_topic.rb', line 45

belongs_to :topic, inverse_of: :party_topics, optional: true