blob: 6ee13ab2a576f1d1e6df0ba6766a050d158058d5 (
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("items.name") }
end
|