Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save pindell-matt/5a91dd9cf997bb8483f9ffe9b5b1b1a7 to your computer and use it in GitHub Desktop.
Save pindell-matt/5a91dd9cf997bb8483f9ffe9b5b1b1a7 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?
Primary Keys are uniq_ids for a table, foreign keys are primary keys featured on a separate table.
#### Where would we find a primary key?
On any table.
#### What would it be called by default?
Id.
#### Where would we find a foreign key?
On a Join Table
#### What is the naming convention for a foreign key?
tablename_id
#### Write down one example of:
* a `one-to-one `relationship: Person-to-Fingerprint
* a `one-to-many relationship`: Bag-to-Cheetos
* a `many-to-many relationship`: People-to-Cheetos
#### What's the difference between test, development, and production databases?
They are separate databases, containing different data, for each environment (test, development, and production)
#### How do you create a Rails app form the command line with a postgres database?
rails new appname -d postgresql
rails new appname --database=postgresql
#### What files are greated by typing `rails g model ...`?
The model.rb file, the model_test.rb, a fixture to provide the model_test fake data, and the migration.rb file.
#### What's the difference between typing `rails g model ...` and `rails g migration ...`?
model generates 4 files, model / model_test / fixture / migration file.
migration generates only the migration file.
#### 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 migration RemoveQuantityFromItems quantity:integer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment