about summary refs log tree commit diff stats
path: root/app/models/pokeviewer/species.rb
blob: 400d67911d2824a5616ed1cd056c6dbf890581bb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
module Pokeviewer
  class Species < ApplicationRecord
    extend Enumerize

    has_many :revisions, dependent: :restrict_with_exception

    has_many :pokedex_entries, dependent: :destroy

    validates :name, presence: true, uniqueness: true

    validates :type_1, presence: true

    enumerize :type_1, in: Move::TYPES
    enumerize :type_2, in: Move::TYPES

    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