Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save notmarkmiranda/4997e25987079ea026fb79b9259c8fa2 to your computer and use it in GitHub Desktop.
Save notmarkmiranda/4997e25987079ea026fb79b9259c8fa2 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 a unique identifier in Table. It can exist as a foreign key in AnotherTable or other tables with which it has a relationship. "id" - default name. "table_id" in AnotherTable.
#### Write down one example of:
* Instructor has one office, computer has one charger
#### Write down two examples of a one-to-many relationship.
* Computer has many usb ports, company has many full time employees
#### Write down two examples of 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?
* test runs in the test environment, when running your test files.
* development runs when we launch the app from our computers via shotgun/rackup/rails s
* production runs when you upload the app to a server
#### How do you create a Rails app fromt he command line with a postgres database?
* rails new project_name --database=postgresql
#### What files are created by typing ```rails g model ...``` ?
* migration, model file, test file, and fixtures
#### What is the difference between typing ```rails g model``` and ```rails g migration```?
* model generates files needed for the model, migration and testing, migration only creates the migration file.
#### Imagine that ```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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment