summaryrefslogtreecommitdiff
path: root/app/models/character_item.rb
blob: 5bc27c9e7e91fcf0716fdb48b9baf71dfc509de7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class CharacterItem < ApplicationRecord
  include DestroyIfZeroQuantity

  belongs_to :character
  belongs_to :item
  validates :quantity, presence: true

  after_initialize do
    if self.new_record?
      self.quantity ||= 0
    end
  end

  scope :ordered_by_item_name, -> { includes(:item).order("LOWER(items.name)").references(:items) }
end