diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/pokeviewer/location.rb | 2 | ||||
-rw-r--r-- | app/models/pokeviewer/pokemon.rb | 12 |
2 files changed, 6 insertions, 8 deletions
diff --git a/app/models/pokeviewer/location.rb b/app/models/pokeviewer/location.rb index e497cbc..db37df2 100644 --- a/app/models/pokeviewer/location.rb +++ b/app/models/pokeviewer/location.rb | |||
@@ -1,5 +1,7 @@ | |||
1 | module Pokeviewer | 1 | module Pokeviewer |
2 | class Location < ApplicationRecord | 2 | class Location < ApplicationRecord |
3 | has_many :pokemon, dependent: :nullify | ||
4 | |||
3 | validates :name, presence: true | 5 | validates :name, presence: true |
4 | end | 6 | end |
5 | end | 7 | end |
diff --git a/app/models/pokeviewer/pokemon.rb b/app/models/pokeviewer/pokemon.rb index 6c33406..9f0b4af 100644 --- a/app/models/pokeviewer/pokemon.rb +++ b/app/models/pokeviewer/pokemon.rb | |||
@@ -24,6 +24,10 @@ module Pokeviewer | |||
24 | validates :met_type, presence: true | 24 | validates :met_type, presence: true |
25 | enumerize :met_type, in: [:normal, :hatched, :npc_trade, :fateful_encounter] | 25 | enumerize :met_type, in: [:normal, :hatched, :npc_trade, :fateful_encounter] |
26 | 26 | ||
27 | belongs_to :location, optional: true | ||
28 | validates :location, presence: true, | ||
29 | if: Proc.new { |c| c.met_type == :normal or c.met_type == :hatched} | ||
30 | |||
27 | validates :gender, presence: true | 31 | validates :gender, presence: true |
28 | enumerize :gender, in: [:genderless, :female, :male] | 32 | enumerize :gender, in: [:genderless, :female, :male] |
29 | 33 | ||
@@ -105,14 +109,6 @@ module Pokeviewer | |||
105 | (trainer.nil?) or (ot_name != trainer.name) or (ot_number != trainer.number) | 109 | (trainer.nil?) or (ot_name != trainer.name) or (ot_number != trainer.number) |
106 | end | 110 | end |
107 | 111 | ||
108 | def location | ||
109 | if (met_type == :normal) or (met_type == :hatched) | ||
110 | Location.find_by_id(met_location) | ||
111 | else | ||
112 | nil | ||
113 | end | ||
114 | end | ||
115 | |||
116 | def display_ot_number | 112 | def display_ot_number |
117 | ot_number.to_s.rjust(5, '0') | 113 | ot_number.to_s.rjust(5, '0') |
118 | end | 114 | end |