Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save JaredRoth/7c33a8801d0fb75994a44ff47e44cf08 to your computer and use it in GitHub Desktop.
Save JaredRoth/7c33a8801d0fb75994a44ff47e44cf08 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 determines uniqueness of an entry in a table (generally, but not necessarily "id")
  • Foreign key references an entry in another table (by its primary key) ("foreignTableName_id")

Write down one example of:

  • Spouses/Couples, Person-SSN,
  • House-Occupants, School-Students
  • Albums-Artists, Students-Classes, Video Games-Players

What's the difference between test, development, and production databases?

  • Test is for running your test suite, generally wiped during each test2
  • Development is for interacting during development
  • Production is for the live data from the real world

How do you create a Rails app from the command line with a postgres database

  • rails new appname -d postgresql

What files are created by typing rails g model ...?

  • A migration
  • A model
  • A model test
  • Fixtures
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment