about summary refs log tree commit diff stats
path: root/app/models
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2017-10-03 15:11:00 -0400
committerKelly Rauchenberger <fefferburbia@gmail.com>2017-10-03 15:11:00 -0400
commitb618e52428bb659cb1fe3bdbe3d3763d48b4556c (patch)
tree58446ae6883c4257013bc93375cfd668720bce95 /app/models
parent34830f2e96e4213e8acb10ea457244c7523aeb5a (diff)
downloadpokeviewer-b618e52428bb659cb1fe3bdbe3d3763d48b4556c.tar.gz
pokeviewer-b618e52428bb659cb1fe3bdbe3d3763d48b4556c.tar.bz2
pokeviewer-b618e52428bb659cb1fe3bdbe3d3763d48b4556c.zip
Made "met location" into an actual association
Diffstat (limited to 'app/models')
-rw-r--r--app/models/pokeviewer/location.rb2
-rw-r--r--app/models/pokeviewer/pokemon.rb12
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 @@
1module Pokeviewer 1module 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
5end 7end
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