From b618e52428bb659cb1fe3bdbe3d3763d48b4556c Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Tue, 3 Oct 2017 15:11:00 -0400 Subject: Made "met location" into an actual association --- app/models/pokeviewer/location.rb | 2 ++ app/models/pokeviewer/pokemon.rb | 12 ++++-------- 2 files changed, 6 insertions(+), 8 deletions(-) (limited to 'app/models') 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 @@ module Pokeviewer class Location < ApplicationRecord + has_many :pokemon, dependent: :nullify + validates :name, presence: true end 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 validates :met_type, presence: true enumerize :met_type, in: [:normal, :hatched, :npc_trade, :fateful_encounter] + belongs_to :location, optional: true + validates :location, presence: true, + if: Proc.new { |c| c.met_type == :normal or c.met_type == :hatched} + validates :gender, presence: true enumerize :gender, in: [:genderless, :female, :male] @@ -105,14 +109,6 @@ module Pokeviewer (trainer.nil?) or (ot_name != trainer.name) or (ot_number != trainer.number) end - def location - if (met_type == :normal) or (met_type == :hatched) - Location.find_by_id(met_location) - else - nil - end - end - def display_ot_number ot_number.to_s.rjust(5, '0') end -- cgit 1.4.1