Class: TopicResponse

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

Overview

== Schema Information

Table name: topic_responses
Database name: primary

id :integer not null, primary key
active :boolean default(TRUE), not null
description :text
position :integer
response :string(255)
score :integer default(0), not null
employee_id :integer
topic_id :integer not null

Indexes

idx_topic_id_active (topic_id,active)
idx_topic_id_score (topic_id,score)

Foreign Keys

topic_responses_topic_id_fk (topic_id => topics.id) ON DELETE => cascade

Constant Summary collapse

USED_RESPONSE_SQL =
<<-EOS
  exists(
    select 1 from party_topics_topic_responses pttr
    where pttr.topic_response_id = topic_responses.id
  )
EOS
USED_RESPONSE_CONTACT_SQL =
<<-EOS
  exists(
    select 1 from party_topics_topic_responses pttr
    inner join party_topics pt on pt.id = pttr.customer_topic_id
    inner join parties p on p.id = pt.party_id
    where p.type = 'Contact'
          and pttr.topic_response_id = topic_responses.id
  )
EOS

Constants included from Models::Auditable

Models::Auditable::ALWAYS_IGNORED

Belongs to collapse

Methods included from Models::Auditable

#creator, #updater

Has and belongs to many collapse

Class 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

.activeActiveRecord::Relation<TopicResponse>

A relation of TopicResponses that are active. Active Record Scope

Returns:

See Also:



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

scope :active, -> { where(active: true) }

.format_for_select(relation = nil) ⇒ Object



71
72
73
74
75
76
77
# File 'app/models/topic_response.rb', line 71

def self.format_for_select(relation = nil)
	relation ||= active
	relation.joins(:topic => :topic_category).
	select("distinct topic_categories.name as topic_category, topics.title as topic_title, topic_responses.response, topic_responses.id").
	order("topics.title, topic_responses.response").
	map{ |tr| ["#{tr.topic_category} : #{tr.topic_title} : #{tr.response}", tr.id] }
end

.possible_responses_for_selectObject



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

def self.possible_responses_for_select
	format_for_select all
end

.used_responsesActiveRecord::Relation<TopicResponse>

A relation of TopicResponses that are used responses. Active Record Scope

Returns:

See Also:



55
# File 'app/models/topic_response.rb', line 55

scope :used_responses, -> { where(USED_RESPONSE_SQL) }

.used_responses_by_contactActiveRecord::Relation<TopicResponse>

A relation of TopicResponses that are used responses by contact. Active Record Scope

Returns:

See Also:



56
# File 'app/models/topic_response.rb', line 56

scope :used_responses_by_contact, -> { where(USED_RESPONSE_CONTACT_SQL) }

.used_responses_by_contact_for_selectObject



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

def self.used_responses_by_contact_for_select
	format_for_select used_responses_by_contact
end

.used_responses_for_selectObject



59
60
61
# File 'app/models/topic_response.rb', line 59

def self.used_responses_for_select
	format_for_select used_responses
end

Instance Method Details

#customer_topicsActiveRecord::Relation<CustomerTopic>

Returns:

See Also:



32
# File 'app/models/topic_response.rb', line 32

has_and_belongs_to_many :customer_topics, inverse_of: :topic_responses

#employeeEmployee

Returns:

See Also:



31
# File 'app/models/topic_response.rb', line 31

belongs_to :employee, optional: true

#topicTopic

Returns:

See Also:



30
# File 'app/models/topic_response.rb', line 30

belongs_to :topic