From 56f5841d4b9c12296cdfcaeff174b2627d59afc8 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sat, 7 Dec 2024 11:49:49 -0500 Subject: Migrate to full rails app --- app/models/species.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 app/models/species.rb (limited to 'app/models/species.rb') diff --git a/app/models/species.rb b/app/models/species.rb new file mode 100644 index 0000000..0623f11 --- /dev/null +++ b/app/models/species.rb @@ -0,0 +1,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 -- cgit 1.4.1