The document appears to be notes from a Ruby on Rails modeling workshop. It includes instructions for generating models for a Wiki application, with User, Page, Comment, and History models. It also includes model validations, tests, associations and notes on Active Record features like migrations, validations, callbacks, associations, and querying.
1 of 42
Download to read offline
More Related Content
Rails3 ΏrModel
1. Model
Hamamatsurb#5 2011.07.13 @mackato
2011 7 13
8. Model
- Ruby on Rails Guides
Rails Database Migrations: http://bit.ly/rrH5zQ
Active Record Validations and Callbacks: http://bit.ly/qp5vkm
Active Record Associations: http://bit.ly/n3exu9
Active Record Query Interface: http://bit.ly/qaeazJ
2011 7 13
9. Version 1.9.2
Version 3.0.7
.rvmrc
rvm ruby-1.9.2-p180@rails-3_0_7
2011 7 13
37. The belongs_to Association The has_many :through Association
class ?Order ?< ?ActiveRecord::Base
? ?belongs_to ?:customer class ?Physician ?< ?ActiveRecord::Base
end ? ?has_many ?:appointments
? ?has_many ?:patients, ?:through ?=> ?:appointments
end
The has_one Association ?
class ?Appointment ?< ?ActiveRecord::Base
class ?Supplier ?< ?ActiveRecord::Base ? ?belongs_to ?:physician
? ?has_one ?:account ? ?belongs_to ?:patient
end end
?
class ?Patient ?< ?ActiveRecord::Base
? ?has_many ?:appointments
The has_many Association ? ?has_many ?:physicians, ?:through ?=> ?:appointments
end
class ?Customer ?< ?ActiveRecord::Base
? ?has_many ?:orders
end
: Active Record Associations: http://bit.ly/n3exu9
2011 7 13
38. Finder methods Retrieving a Single Object
? where
? select
? group
? order Retrieving Multiple Objects
? limit
? offset
? joins
? includes
? lock Calculations
? readonly
? from
? having
Active Record Query Interface: http://bit.ly/qaeazJ
2011 7 13