summaryrefslogtreecommitdiff
path: root/app/models/license.rb
blob: 77aad5fea3130da8ee1137fc9c9d91ade2b41f17 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class License < ActiveRecord::Base
  belongs_to :company
  belongs_to :well_type
  has_one :location
  belongs_to :applicant, class_name: 'User', foreign_key: 'user_id'

  def self.most_recent(page: 1, per_page: 10)
    offset = (page - 1) * per_page
    offset = offset >= 0 ? offset : 0
    License.order(created_at: :desc).offset(offset).limit(per_page)
  end

  def self.township(township)
    joins(:location).where('locations.township = ?', township)
  end

  def self.status(status)
    status.filter(self)
  end
end