Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bethsebian/2a8243fc32b03b0d1183 to your computer and use it in GitHub Desktop.
Save bethsebian/2a8243fc32b03b0d1183 to your computer and use it in GitHub Desktop.
What is the difference between a primary key and a foreign key?
Primary key is the unique identifier for an entry in a table. A foreign key is a value in a table that references the primary key of another table.
Where would we find a primary key?
Generally in the first column of a table.
What would it be called by default?
id
Where would we find a foreign key?
In a column of another table. Could be anywhere, I think normally a column near the end?
What is the naming convention for a foreign key?
table_name_being_referenced and id_number
1-to-1: special snowflake has special design
1-to-many: Italian has many gondolas
many-to-many: immigrants have many countries
What's the difference between test, development, and production databases?
Test is where data is stored from commands written in your test files.
Development is where data is stored when you're writing code and adding data through terminal.
Production is where data is stored when users interact with your site.
How do you create a Rails app from the command line with a postgres database?
rails new appname --database=postgresql
What files are created by typing rails g model ...?
Migration, model, model test, fixture test
What's the difference between typing rails g model ... and rails g migration ...?
Rails g migration only creates the migration, while Rails g model will create both the migration and the model.
Imagine that the items table has a category called quantity. What command would you type if you wanted to get rid of the quantity attribute?
Rails g RemoveQuantityFromItems quantity:integer
Imagine that you have a table students. What is the ActiveRecord query that would return all students with the first name of Richard?
Student.where(first_name: 'Richard')
Student.find_by(id: 4).update(phone: "101-222-3333")
How would you update the student record with ID 4 to have a new phone number of "101-222-3333"?
Student.find_by(id: 4).update(phone: "101-222-3333")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment