Skip to content

Instantly share code, notes, and snippets.

@torsday
Last active December 16, 2015 10:39
Show Gist options
  • Save torsday/5421689 to your computer and use it in GitHub Desktop.
Save torsday/5421689 to your computer and use it in GitHub Desktop.
Active Record #notes

Active Record


Active Record tracks which migrations have already been run so all you have to do is update your source and run rake db:migrate. Active Record will work out which migrations should be run. It will also update your db/schema.rb file to match the structure of your database.

INDEX


INBOX


  • migrations for schema creation

  • validations

  • one-to-may association

  • many-to-many association

  • spec tests

  • Schema

  • Associations

  • Migrations

    • symmetric
  • TDD models and migrations

  • Scrub and import data

  • AR queries

  • single-table inheritance

  • internalize schema

class AddCanFireMissilesFlagToUsers < ActiveRecord::Migration
  def change
    add_column :users, :can_fire_missiles, :boolean, :default => false
  end
end

Migrations


Supported database column types:*

  • binary
  • boolean
  • date
  • datetime
  • decimal
  • float
  • integer
  • primary_key
  • string
  • text
  • time
  • timestamp

Migrations are classes

Active Record provides methods that perform common data definition tasks in a database independent way:

  • add_column
  • add_index
  • change_column
  • change_table
  • create_table
  • drop_table
  • remove_column
  • remove_index
  • rename_column

REFERENCES


Related Projects


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