Embed
Email

Ruby on Rails : active record cheat sheet

Document Sample
Ruby on Rails : active record cheat sheet
Shared by: Jigar Chauhan
Stats
views:
125
posted:
8/27/2009
language:
English
pages:
1
Actuiby on Rails cheat aR

belongs to

create table customers ( id int auto_increment primary key, name varchar(75), company_id int )



onysHhoips dsh
Reegluaetbiy Am y veRecor e t id

has many



note: has_many and has_one work identically except for the number of relationships. both go on the table/model that does not feature the foreign key



create table companies ( id int auto_increment primary key, name varchar(75) )



customers belongs_to :company

company_id



companies has_many :customers

id



has and belongs to many

create table articles ( id int auto_increment primary key, name varchar(75), body text ) create table authors ( id int auto_increment primary key, name varchar(75) ) create table articles_authors ( author_id int, article_id int )



articles



has_and_belongs_to_many :authors

id



authors articles_authors

article_id author_id id



has_and_belongs_to_many :articles



note: the articles_authors table is implicit due to the two models that call habtm, and it does not require a model of its own. when making implicit mapping tables such as this, it must be named tablea_tableb where a is first in alphabetical order.

© 2005 Amy Hoy / amy@infocookie.com / www.slash7.com MIT License — see http://www.slash7.org/cheats/license.html





Related docs
Other docs by Jigar Chauhan
JavaScript cheat sheet V1
Views: 56  |  Downloads: 6
ruby-on-rails-cheat-sheet-v1
Views: 64  |  Downloads: 4
Ruby on Rails : active record cheat sheet
Views: 125  |  Downloads: 17
SEO Web Developer CheatSheet
Views: 41  |  Downloads: 7
Ruby on Rails for PHP and Java Developers
Views: 2308  |  Downloads: 55
jQuery1.2 cheatsheet.v1.0
Views: 106  |  Downloads: 4
64 CSS Cheats
Views: 103  |  Downloads: 5
CSS Cheatsheet Version 2
Views: 63  |  Downloads: 23
Rails Files Cheatsheet
Views: 57  |  Downloads: 5
Mobile Web Design Guide
Views: 567  |  Downloads: 85
By registering with docstoc.com you agree to our
privacy policy

You are almost ready to download!

You are almost ready to download!