Module: Fera::BelongsToSubmission

Extended by:
ActiveSupport::Concern
Included in:
Media, Review
Defined in:
lib/fera/models/concerns/belongs_to_submission.rb

Instance Method Summary collapse

Instance Method Details

#submissionObject



26
27
28
29
30
31
32
33
34
# File 'lib/fera/models/concerns/belongs_to_submission.rb', line 26

def submission
  if @submission.present?
    @submission
  elsif attributes.key?('submission') && attributes['submission'].present?
    Submission.new(attributes['submission'], true)
  elsif attributes.key?('submission_id') && submission_id.present?
    Submission.find(submission_id)
  end
end

#submission=(submission) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/fera/models/concerns/belongs_to_submission.rb', line 11

def submission=(submission)
  submission_id = if submission.is_a?(Submission)
                    submission.id
                  else
                    submission.try(:with_indifferent_access).try(:[], :id)
                  end
  @submission = if submission.is_a?(Submission)
                  submission
                else
                  Submission.new(submission, submission_id.present?)
                end
  self.attributes['submission_id'] = submission_id
  self.attributes.delete('submission')
end