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