Forked from Carmer/ModelsDatabasesRelationships.md
Last active
April 5, 2016 19:35
-
-
Save lingtran/524e2d952049d03da4ceb0335d580979 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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 Tables. It can exist as a foreign key in AnotherTables or other tables with which it has a relationship. "id" - default name. "table_id" in AnotherTables. | |
#### Write down one example of: | |
* a `one-to-one `relationship: (current democratic society enables) one country has one president | |
* a `one-to-many relationship': one country has many citizens | |
* a `many-to-many relationship`: (given current industrial agricultural norms...I assume...) each agricultural crop has many producers, each producer has many agricultural crops | |
#### What's the difference between test, development, and production databases? | |
* Test database holds data utilized when the environment is testing. Data is loaded in. Its purpose is to enable the development team to test functionality with fake data. | |
* Development database holds data that is created and updated, etc. when the environment is in development. This means that there are people interacting with application but still in a controlled sense. | |
* Production database create, update, etc. data when the application is live and so there may be a combo of indirect and direct impact on the data from an external user utilizing the application. "Sacred" database. Do not delete production data. | |
* Each environment represents different states of an application. | |
#### How do you create a Rails app from the command line with a postgres database? | |
``` rails new [app_name] --database=postgresql ``` | |
``` rails new [app_name] --d=postsgresql ``` | |
#### What files are created by typing rails g model ...? | |
* rails g model ... == rails generate model ... | |
* files created: 2 test files (fixture, test), model, migration file | |
#### What's the difference between typing rails g model ... and rails g migration ...? | |
* rails g model generates four files related to the model specified, which are two test files (fixtures, test), model file, and a migration file | |
* rails g migration performs ActiveRecord migration actions, which include creating migration files and updating the schema. | |
#### 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 RemoveQuantityColumninItems quantity:integer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment