about summary refs log tree commit diff stats
path: root/app/models
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2018-01-29 21:13:35 -0500
committerKelly Rauchenberger <fefferburbia@gmail.com>2018-01-29 21:13:35 -0500
commit5ade37d852bd1e96f9451ab98619359a5a048cee (patch)
tree251c6bf7c24b7be69b2e908590a733a808165e4c /app/models
parent30cd66e1521bc760df45908adb2f7d3ba6683900 (diff)
downloadpokeviewer-5ade37d852bd1e96f9451ab98619359a5a048cee.tar.gz
pokeviewer-5ade37d852bd1e96f9451ab98619359a5a048cee.tar.bz2
pokeviewer-5ade37d852bd1e96f9451ab98619359a5a048cee.zip
Added Pokédex viewing page
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.
Diffstat (limited to 'app/models')
-rw-r--r--app/models/pokeviewer/pokedex_entry.rb6
-rw-r--r--app/models/pokeviewer/species.rb9
-rw-r--r--app/models/pokeviewer/trainer.rb2
3 files changed, 17 insertions, 0 deletions
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 @@
1module Pokeviewer
2 class PokedexEntry < ApplicationRecord
3 belongs_to :trainer
4 belongs_to :species
5 end
6end
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
4 4
5 has_many :revisions, dependent: :restrict_with_exception 5 has_many :revisions, dependent: :restrict_with_exception
6 6
7 has_many :pokedex_entries, dependent: :destroy
8
7 validates :name, presence: true, uniqueness: true 9 validates :name, presence: true, uniqueness: true
8 10
9 validates :type_1, presence: true 11 validates :type_1, presence: true
@@ -13,5 +15,12 @@ module Pokeviewer
13 15
14 belongs_to :ability_1, class_name: "Ability" 16 belongs_to :ability_1, class_name: "Ability"
15 belongs_to :ability_2, class_name: "Ability", optional: true 17 belongs_to :ability_2, class_name: "Ability", optional: true
18
19 def current_revisions
20 revisions.
21 where("pokeviewer_pokemon.current_id = pokeviewer_revisions.id").
22 includes(:pokemon).
23 references(:pokemon)
24 end
16 end 25 end
17end 26end
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
4 4
5 has_many :pokemon, dependent: :nullify 5 has_many :pokemon, dependent: :nullify
6 6
7 has_many :pokedex_entries, dependent: :destroy
8
7 validates :number, presence: true, 9 validates :number, presence: true,
8 numericality: { greater_than_or_equal_to: 0, only_integer: true } 10 numericality: { greater_than_or_equal_to: 0, only_integer: true }
9 11