From 5ade37d852bd1e96f9451ab98619359a5a048cee Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Mon, 29 Jan 2018 21:13:35 -0500 Subject: Added Pokédex viewing page MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently a work in progress. The queries used to display the Pokémon for each species are very inefficient. The text at the top of the page is also very specific to the author. --- app/models/pokeviewer/pokedex_entry.rb | 6 ++++++ app/models/pokeviewer/species.rb | 9 +++++++++ app/models/pokeviewer/trainer.rb | 2 ++ 3 files changed, 17 insertions(+) create mode 100644 app/models/pokeviewer/pokedex_entry.rb (limited to 'app/models') diff --git a/app/models/pokeviewer/pokedex_entry.rb b/app/models/pokeviewer/pokedex_entry.rb new file mode 100644 index 0000000..9be6a6a --- /dev/null +++ b/app/models/pokeviewer/pokedex_entry.rb @@ -0,0 +1,6 @@ +module Pokeviewer + class PokedexEntry < ApplicationRecord + belongs_to :trainer + belongs_to :species + end +end diff --git a/app/models/pokeviewer/species.rb b/app/models/pokeviewer/species.rb index aae66cc..400d679 100644 --- a/app/models/pokeviewer/species.rb +++ b/app/models/pokeviewer/species.rb @@ -4,6 +4,8 @@ module Pokeviewer has_many :revisions, dependent: :restrict_with_exception + has_many :pokedex_entries, dependent: :destroy + validates :name, presence: true, uniqueness: true validates :type_1, presence: true @@ -13,5 +15,12 @@ module Pokeviewer belongs_to :ability_1, class_name: "Ability" belongs_to :ability_2, class_name: "Ability", optional: true + + def current_revisions + revisions. + where("pokeviewer_pokemon.current_id = pokeviewer_revisions.id"). + includes(:pokemon). + references(:pokemon) + end end end diff --git a/app/models/pokeviewer/trainer.rb b/app/models/pokeviewer/trainer.rb index 0ea12c8..950dac0 100644 --- a/app/models/pokeviewer/trainer.rb +++ b/app/models/pokeviewer/trainer.rb @@ -4,6 +4,8 @@ module Pokeviewer has_many :pokemon, dependent: :nullify + has_many :pokedex_entries, dependent: :destroy + validates :number, presence: true, numericality: { greater_than_or_equal_to: 0, only_integer: true } -- cgit 1.4.1