summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorDavid Gay <david@davidgay.org>2021-06-15 21:52:49 -0400
committerDavid Gay <david@davidgay.org>2021-06-15 21:54:32 -0400
commit637adf2963f174c3e3e3d6cf9efbff314e306f3e (patch)
tree4e4812f66848a751b12adda81f7c500c0a689116 /app/models
parentf637f622af2d9b891271344ef23402c41419b3fe (diff)
MonsterKills and bestiary view
Diffstat (limited to 'app/models')
-rw-r--r--app/models/character.rb1
-rw-r--r--app/models/monster_kill.rb7
2 files changed, 8 insertions, 0 deletions
diff --git a/app/models/character.rb b/app/models/character.rb
index 0f2c5b3..7f26ad4 100644
--- a/app/models/character.rb
+++ b/app/models/character.rb
@@ -14,6 +14,7 @@ class Character < ApplicationRecord
has_many :conditions, through: :states
has_many :states
has_many :chat_messages
+ has_many :monster_kills
has_many :bazaar_orders
validates :name, presence: true
# TODO: Make defaults better. This has to allow nil so the `attribute` default works, and I don't like that.
diff --git a/app/models/monster_kill.rb b/app/models/monster_kill.rb
new file mode 100644
index 0000000..4096e8e
--- /dev/null
+++ b/app/models/monster_kill.rb
@@ -0,0 +1,7 @@
+class MonsterKill < ApplicationRecord
+ belongs_to :monster
+ belongs_to :character
+
+ validates :quantity, numericality: { greater_than_or_equal_to: 0, only_integer: true }
+ scope :ordered_by_monster_name, -> { includes(:monster).order("monsters.name") }
+end