app/models/decidim/forms/answer.rb in decidim-forms-0.23.6 vs app/models/decidim/forms/answer.rb in decidim-forms-0.24.0.rc1
- old
+ new
@@ -4,10 +4,11 @@
module Forms
# The data store for an Answer in the Decidim::Forms
class Answer < Forms::ApplicationRecord
include Decidim::DataPortability
include Decidim::NewsletterParticipant
+ include Decidim::HasAttachments
belongs_to :user, class_name: "Decidim::User", foreign_key: "decidim_user_id", optional: true
belongs_to :questionnaire, class_name: "Questionnaire", foreign_key: "decidim_questionnaire_id"
belongs_to :question, class_name: "Question", foreign_key: "decidim_question_id"
@@ -18,10 +19,12 @@
inverse_of: :answer
validate :user_questionnaire_same_organization
validate :question_belongs_to_questionnaire
+ scope :not_separator, -> { joins(:question).where.not(decidim_forms_questions: { question_type: Decidim::Forms::Question::SEPARATOR_TYPE }) }
+
def self.user_collection(user)
where(decidim_user_id: user.id)
end
def self.export_serializer
@@ -35,9 +38,14 @@
answers = Decidim::Forms::Answer.joins(:questionnaire)
.where(questionnaire: questionnaires)
answers.pluck(:decidim_user_id).flatten.compact.uniq
+ end
+
+ def organization
+ user.organization if user.present?
+ questionnaire&.questionnaire_for.try(:organization)
end
private
def user_questionnaire_same_organization