Refactors in poll/question model

This commit is contained in:
kikito
2016-11-11 19:10:36 +01:00
parent 0c9e6db04d
commit 11a98dce07

View File

@@ -9,6 +9,7 @@ class Poll::Question < ActiveRecord::Base
has_many :comments, as: :commentable
has_many :answers
has_many :partial_results
has_and_belongs_to_many :geozones
belongs_to :proposal
@@ -21,7 +22,7 @@ class Poll::Question < ActiveRecord::Base
validates :description, length: { maximum: Poll::Question.description_max_length }
validates :question, length: { in: 10..Poll::Question.question_max_length }
scope :sort_for_list, -> { order('proposal_id IS NULL', :created_at)}
scope :sort_for_list, -> { order('poll_questions.proposal_id IS NULL', :created_at)}
scope :for_render, -> { includes(:author, :proposal) }
scope :by_geozone, -> (geozone_id) { joins(:geozones).where(geozones: {id: geozone_id}) }