Just like we do in the Budget module, and in some places in the Poll and Legislation modules, we don't need to specify the class name when the name of the relation matches the name of a class in the same module.
14 lines
603 B
Ruby
14 lines
603 B
Ruby
class Legislation::Answer < ApplicationRecord
|
|
acts_as_paranoid column: :hidden_at
|
|
include ActsAsParanoidAliases
|
|
|
|
belongs_to :question, foreign_key: "legislation_question_id", inverse_of: :answers, counter_cache: true
|
|
belongs_to :question_option, foreign_key: "legislation_question_option_id",
|
|
inverse_of: :answers, counter_cache: true
|
|
belongs_to :user, dependent: :destroy, inverse_of: :legislation_answers
|
|
|
|
validates :question, presence: true, uniqueness: { scope: :user_id }
|
|
validates :question_option, presence: true
|
|
validates :user, presence: true
|
|
end
|