Module: ModelExtensions::Sample

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object


2
3
4
5
6
7
8
9
10
11
# File 'app/api/model_extensions/sample.rb', line 2

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


13
14
15
# File 'app/api/model_extensions/sample.rb', line 13

def sample_reference_genome_name
  sample_reference_genome.try(:name)
end

#sample_reference_genome_name=(name) ⇒ Object


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

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