Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save drew-t/97ddaa1a143ad13423c128b5e0190fb0 to your computer and use it in GitHub Desktop.
Save drew-t/97ddaa1a143ad13423c128b5e0190fb0 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 can only appear once in a table, foreign key points to an object with a primary key in another table. Primary key is normally called id in postgres.
We would find a foreign key when we reference an object from another table. naming convention: table_id
#### Write down one example of:
* a `one-to-one `relationship.
husband:wife
* a `one-to-many relationship`.
fridge:food
food:ingredients
* a `many-to-many relationship`.
actor/actress:movie
Databases: Test vs Dev vs Production
Test should generally be kept clean and have data added or cleaner as necessary per test.
Dev would be where you are testing with some semi-known data so that you can see what's going on.
Production is your main database that is used by your application.
Command to make rails project with postgres db: `rails new appname --database=postgresql`
Rails g model creates a new model file, a migration, and test files
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment