Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kristindiannefoss/941df5918c2a4c0b69637611b7edf10f to your computer and use it in GitHub Desktop.
Save kristindiannefoss/941df5918c2a4c0b69637611b7edf10f to your computer and use it in GitHub Desktop.
## Models, Databases, Relationships in Rails
#### What is the difference between a primary key and a foreign key? Where would we find a primary key?
What would it be called by default? Where would we find a foreign key? What is the naming convention for a foreign key?
Primary key is the id in the table you're working in, the foreign key is the connected key from another table you're
joining or referencing in the current table. The primary key is generated when the table is created. Primary cannot be
repeated in the table. Foreign key is a relationship that is formed, primary key of another table. Name of table_id is
convention for the foreign key.
#### Write down one example of:
* a `one-to-one `relationship.
Instructor has one office, computer has one charger
* a `one-to-many relationship`.
Computer has many usb ports, company has many full time employees
* a `many-to-many relationship`.
Many turing students have many instructors, many grocery stores have many customers
What's the difference between test, development, and production databases?
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 file, model file, test file for that model and a yml database file.
What's the difference between typing rails g model ... and rails g migration ...?
rails g model just creates a model, vs migration which runs all the migrations.
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?
type remove_column in the migration file, then the table name, then column to remove
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment