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 :integer
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 =
%i[assigned in_progress completed cancelled]

Constants included from Models::Auditable

Models::Auditable::ALWAYS_IGNORED

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 Models::EventPublishable

#publish_event

Class Method Details

.assignedActiveRecord::Relation<PartyTopic>

A relation of PartyTopics that are assigned. Active Record Scope

Returns:

See Also:



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

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

.completedActiveRecord::Relation<PartyTopic>

A relation of PartyTopics that are completed. Active Record Scope

Returns:

See Also:



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

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

.examsActiveRecord::Relation<PartyTopic>

A relation of PartyTopics that are exams. Active Record Scope

Returns:

See Also:



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

scope :exams, -> { where.not(topic_exam_id: nil)}

.for_topic_categoryActiveRecord::Relation<PartyTopic>

A relation of PartyTopics that are for topic category. Active Record Scope

Returns:

See Also:



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

scope :for_topic_category, -> (tc) { where(party_topics: {topic_category_id: tc.id}).sorted}

.in_progressActiveRecord::Relation<PartyTopic>

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

Returns:

See Also:



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

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

.no_examsActiveRecord::Relation<PartyTopic>

A relation of PartyTopics that are no exams. Active Record Scope

Returns:

See Also:



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

scope :no_exams, -> { where.not(topic_category_id: nil)}

.ongoingActiveRecord::Relation<PartyTopic>

A relation of PartyTopics that are ongoing. Active Record Scope

Returns:

See Also:



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

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

.sortedActiveRecord::Relation<PartyTopic>

A relation of PartyTopics that are sorted. Active Record Scope

Returns:

See Also:



55
56
# File 'app/models/party_topic.rb', line 55

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

Instance Method Details

#completeObject



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

def complete
  self.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:



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

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