Forked from Carmer/ModelsDatabasesRelationships.md
Last active
April 5, 2016 19:31
-
-
Save Jbern16/19b16f433b4084b68e217452018ca0ba to your computer and use it in GitHub Desktop.
This file contains 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? | |
We find a primary key as the main identifier of a table. Example: Teachers: TeacherId. A Foreign creates the relationship between tables. | |
Example: Teachers : course_id. The naming convention for these are the table they belong to + "_id" | |
#### Write down one example of: | |
* a `one-to-one `relationship. | |
each person has one toothbrush and one toothbrush has one person. This is modeled by combining both to a single table because they are | |
dependent of eachother | |
* a `one-to-many relationship`. | |
Person can have many pants, but pants have one person.. Always in a one-to-many relationship, the many gets the foreign_key of the one | |
* a `many-to-many relationship`. | |
A Book can have many authors and an author can have many books. This is modeled by creating a join table of each tables primary key | |
### How do you create a rails app from the command line with postgres database? | |
rails new appname --database=postgresql | |
### Whats the difference between test, devleopment and production databases? | |
depending where you are sending the data from (test, dev, production) it will be stored in a seperare database. By keeping these seperate, | |
you can have specific databases and limit confusion. You wouldn't want test data in your production database. | |
## What files are created by typing rails g model | |
it created the model, migration, fixtures and model test file. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment