Module: Aliquot::Aliquotable

Included in:
Sample
Defined in:
app/models/aliquot/aliquotable.rb

Overview

Something that is aliquotable can be part of an aliquot. So sample and tag are both examples.

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object


3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/models/aliquot/aliquotable.rb', line 3

def self.included(base)
  base.class_eval do
    extend ClassMethods

    has_many :aliquots
    has_many :receptacles, ->() { distinct }, through: :aliquots
    has_one :primary_aliquot, ->() { order('created_at ASC, aliquots.id ASC').readonly }, class_name: 'Aliquot'
    has_one :primary_receptacle, ->() { order('aliquots.created_at ASC, aliquots.id ASC') }, through: :primary_aliquot, source: :receptacle

    has_many :requests, through: :assets
    has_many :submissions, through: :requests

    scope :contained_in, ->(receptacles) { joins(:receptacles).where(assets: { id: receptacles }) }
  end
end