Forked from Carmer/ModelsDatabasesRelationships.md
Last active
April 5, 2016 18:02
-
-
Save patrickwhardy/4c6ae573845cfa2c2815b2e81845c461 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 lives on the one side of a one to many relationship. It is generally called tablename_id. The "many" object in the relationship holds on to a forieign key that uniqely identifies it's "one" association. | |
#### Write down one example of: | |
* a `one-to-one `relationship. | |
* Citizen to SSN | |
* One king to one kingdom | |
* a `one-to-many relationship`. | |
* One kingdom has many peasants | |
* a `many-to-many relationship`. | |
* Each crop has many peasants that raised it, each peasant has many crops he/she raised | |
* Test database is modified and accessed when running tests | |
* Development databases are interacted with in the same way as the production database, but data is stored independent of production. | |
* Production database stores real client data | |
#Creating a Rails app | |
* rails new project_name --database=postgresql | |
#rails g model | |
*this creates a a migration file with a create_table :models command | |
#rails g migration | |
*this generates a new migration that joins tables | |
#how to remove column | |
*rails g migration RemoveColumnfromItems quantity:integer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment