car.rb 757 字节
Newer Older
1
class Car < ActiveRecord::Base
2

3
  has_many :bulbs
4
  has_many :foo_bulbs, :class_name => "Bulb", :conditions => { :name => 'foo' }
5 6
  has_many :frickinawesome_bulbs, :class_name => "Bulb", :conditions => { :frickinawesome => true }

7 8 9
  has_one :bulb
  has_one :frickinawesome_bulb, :class_name => "Bulb", :conditions => { :frickinawesome => true }

10
  has_many :tyres
11
  has_many :engines, :dependent => :destroy
12
  has_many :wheels, :as => :wheelable, :dependent => :destroy
13

J
Jon Leighton 已提交
14 15
  scope :incl_tyres, -> { includes(:tyres) }
  scope :incl_engines, -> { includes(:engines) }
16

J
Jon Leighton 已提交
17
  scope :order_using_new_style,  -> { order('name asc') }
18

19
end
20 21

class CoolCar < Car
J
Jon Leighton 已提交
22
  default_scope { order('name desc') }
23 24 25
end

class FastCar < Car
J
Jon Leighton 已提交
26
  default_scope { order('name desc') }
27
end