about summary refs log tree commit diff stats
path: root/app/models/species.rb
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2024-12-07 11:49:49 -0500
committerStar Rauchenberger <fefferburbia@gmail.com>2024-12-07 11:49:49 -0500
commit56f5841d4b9c12296cdfcaeff174b2627d59afc8 (patch)
tree4f7da4ebbe5ee15a1594b26466ed78e2cf10de35 /app/models/species.rb
parentc1b0443ba2aebdbd39291ddab0c189f3f4831320 (diff)
downloadpokeviewer-56f5841d4b9c12296cdfcaeff174b2627d59afc8.tar.gz
pokeviewer-56f5841d4b9c12296cdfcaeff174b2627d59afc8.tar.bz2
pokeviewer-56f5841d4b9c12296cdfcaeff174b2627d59afc8.zip
Migrate to full rails app
Diffstat (limited to 'app/models/species.rb')
-rw-r--r--app/models/species.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/app/models/species.rb b/app/models/species.rb new file mode 100644 index 0000000..0623f11 --- /dev/null +++ b/app/models/species.rb
@@ -0,0 +1,24 @@
1class Species < ApplicationRecord
2 extend Enumerize
3
4 has_many :revisions, dependent: :restrict_with_exception
5
6 has_many :pokedex_entries, dependent: :destroy
7
8 validates :name, presence: true, uniqueness: true
9
10 validates :type_1, presence: true
11
12 enumerize :type_1, in: Move::TYPES
13 enumerize :type_2, in: Move::TYPES
14
15 belongs_to :ability_1, class_name: "Ability"
16 belongs_to :ability_2, class_name: "Ability", optional: true
17
18 def current_revisions
19 revisions.
20 where("pokemon.current_id = revisions.id").
21 includes(:pokemon).
22 references(:pokemon)
23 end
24end