2.6A - Ajout de l'enum

pull/1/head
Karim Bogtob 2 years ago
parent f5bdb92a2a
commit 40770d4240

@ -66,3 +66,8 @@ irb(main):001:0> Creature.create(name: 'Zombie', health_points: 0)
* J'ai bien une 404 et son nom n'a pas changé
Question 2.6 :
* Je génère la migration avec `rails g migration AddSizeColumnToCreatures size:integer`
* `rails db:migrate`

@ -1,7 +1,11 @@
class Creature < ApplicationRecord
scope :alive, -> { where('health_points > 0') }
enum :size, [:small, :big, :giant]
def to_label
"#{name} (#{health_points})"
end
end

@ -0,0 +1,5 @@
class AddSizeColumnToCreatures < ActiveRecord::Migration[7.0]
def change
add_column :creatures, :size, :integer
end
end

3
db/schema.rb generated

@ -10,12 +10,13 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2023_03_26_131540) do
ActiveRecord::Schema[7.0].define(version: 2023_03_26_140343) do
create_table "creatures", force: :cascade do |t|
t.string "name"
t.integer "health_points"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "size"
end
end

Loading…
Cancel
Save