Module: StandardNamedScopes

Included in:
Batch, Request, Sample, SampleTube
Defined in:
app/models/standard_named_scopes.rb

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object


2
3
4
5
6
7
8
9
10
11
12
# File 'app/models/standard_named_scopes.rb', line 2

def self.included(base)
  base.instance_eval do
    # Date ordering is better specified as "order_most_recently_created_first" or
    # "order_most_recently_updated_last".  These names seem more readable and understandable.
    [:created, :updated].each do |field|
      { first: 'DESC', last: 'ASC' }.each do |position, order_by|
        scope :"order_most_recently_#{field}_#{position}", -> { order("#{quoted_table_name}.#{field}_at #{order_by}") }
      end
    end
  end
end