about summary refs log tree commit diff stats
path: root/app/models/species.rb
blob: 0623f11366e159f1372f95a3e52c3aba051d62b2 (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
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("pokemon.current_id = revisions.id").
      includes(:pokemon).
      references(:pokemon)
  end
end