orders |
id |
int |
customer_id |
int |
|
line_items |
id |
int |
order_id |
int |
|
customers |
id |
int |
name |
string |
|
addresses |
id |
int |
customer_id |
int |
|
class Order < ActiveRecord::Base
has_many :line_items
belongs_to :customer end
class LineItem < ActiveRecord::Base
belongs_to :order end
class Customer < ActiveRecord::Base
has_many :orders
has_one :address
end
class Address < ActiveRecord::Base
belongs_to :customer
end
myorder = Order.create(:customer_id => 33)
myorder.customer_id
myorder.name
Order.find(:all)
Company.find(:first, :conditions => [
"id = :id AND name = :name AND division = :division AND created_at > :accounting_date",
{ :id => 3, :name => "37signals", :division => "First", :accounting_date => '2005-01-01' }
])
Student.find(:all, :conditions => { :grade => 9..12 })