Skip to content

Instantly share code, notes, and snippets.

@originalhat
Created November 20, 2012 23:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save originalhat/4122116 to your computer and use it in GitHub Desktop.
Save originalhat/4122116 to your computer and use it in GitHub Desktop.

create a table...

# eq. to: CREATE TABLE nagios_contactgroup (project_id INT, name VARCHAR(255));
create_table :nagios_contactgroup do |t| # create table name
  t.integer :project_id                  # add a column called 'project_id'
  t.string  :name, :null => false        # add a column called 'name', it can't be null
end

add_index :nagios_contactgroup, :project_id # index a column in the 'nagios_contactgroup' table

adding shit to that table...

# INSERT INTO nagios_contactgroup VALUES (project='some_project_id', 'name_some_project_name')
NagiosContactgroup.create( :project => project, :name => project.name ) 

where project is another associated table

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