Module: ModelExtensions::Sample

Included in:
Sample
Defined in:
app/api/model_extensions/sample.rb

Overview

TODO:

Rails relationships should probably be moved to Sample

Included in Sample The intent of this file was to provide methods specific to the V1 API

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object


5
6
7
8
9
10
11
12
13
14
# File 'app/api/model_extensions/sample.rb', line 5

def self.included(base)
  base.class_eval do
    scope :include_studies, -> { includes(studies: :study_metadata) }

    has_one :primary_study_samples, ->() { order(:study_id) }, class_name: 'StudySample'
    has_one :primary_study, through: :primary_study_samples, source: :study
    has_one :primary_study_metadata, through: :primary_study, source: :study_metadata
    has_one :study_reference_genome, through: :primary_study_metadata, source: :reference_genome
  end
end

Instance Method Details

#sample_reference_genome_nameObject


16
17
18
# File 'app/api/model_extensions/sample.rb', line 16

def sample_reference_genome_name
  sample_reference_genome.try(:name)
end

#sample_reference_genome_name=(name) ⇒ Object


20
21
22
# File 'app/api/model_extensions/sample.rb', line 20

def sample_reference_genome_name=(name)
  .reference_genome = ReferenceGenome.find_by(name: name)
end