Object/Relational Mapping
ORM 把datebase table mapping 到class。如果有database table叫orders, 那就有相對應個class叫做Order. tables correspond to classes. rows in a table correspond to objects of the class
- 透過ORM,把database整個物件化,讓我們不用直接存取 database data
example:
order = Order.find(1)
puts "Order #{order.custom_id}, amount=#{order.amount}"
Order.find(:all, :conditions => "name='lake'") do |order|
puts order.amount
order.discount = 0.5
order.save
end
require 'active_record'
class Order <>
沒有留言:
張貼留言