Skip to content

Instantly share code, notes, and snippets.

@jumpcheng
Forked from stujo/orm.md
Last active August 29, 2015 14:21
Show Gist options
  • Save jumpcheng/0f4ddd4fe0ab385bc1aa to your computer and use it in GitHub Desktop.
Save jumpcheng/0f4ddd4fe0ab385bc1aa to your computer and use it in GitHub Desktop.

Object Relational Mapping

Implementation for SQL RDBMS Databases in Ruby

  • Domain Specific Model classes are defined for specific tables
  • Each Model class maps to a table
  • Class methods map to actions on the table
    • find, -> SELECT
  • An instance of the Model class maps to single row in the table
  • An instance may refer to a 'yet-to-be-inserted' row
  • The id ruby property maps to the PRIMARY KEY ID
  • Instance methods map to actions on that single row
    • save -> INSERT or UPDATE
    • destroy -> DELETE

Discussion

  • What about Related Objects?

Optional Code Along

  • cd parksandrec
  • bundle
  • irb -r ./parksandrec.rb

Resources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment