-
Notifications
You must be signed in to change notification settings - Fork 124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add species to pets table and set up enum in the pet model #233
Conversation
@@ -0,0 +1,5 @@ | |||
class AddSpecies2Pets < ActiveRecord::Migration[7.0] | |||
def change | |||
add_column :pets, :species, :integer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add_column :pets, :species, :integer | |
add_column :pets, :species, :integer, null: false |
Adding this null: false
prevents at the database level from allowing rows without the species defined. Helps keep data more accurate in case of issues. This comes especially helpful if validations get skipped
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jadekstewart3 in case you missed this comment :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@edwinthinks I totally did! Thank you, I'll get that updated:)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jadekstewart3 I think the schema.rb
file was not updated with null: false
. Easiest way to regenerate it is to run rails db:rollback
and rails db:migrate
:)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Ptrboro Oh heck! Thank you!
@@ -31,6 +31,7 @@ class Pet < ApplicationRecord | |||
has_many :adopter_applications, dependent: :destroy | |||
has_one :match, dependent: :destroy | |||
has_many_attached :images | |||
enum species: ["dog", "cat"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add quick test for this using shoulda - https://matchers.shoulda.io/docs/v3.1.1/Shoulda/Matchers/ActiveRecord.html#define_enum_for-instance_method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
🔗 Issue
#222
✍️ Description
Added species column to pets table, and setup species enum within the pets model.
📷 Screenshots/Demos