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

3
  has_many :bulbs
4
  has_many :funky_bulbs, class_name: 'FunkyBulb', dependent: :destroy
5 6
  has_many :foo_bulbs, -> { where(:name => 'foo') }, :class_name => "Bulb"
  has_many :frickinawesome_bulbs, -> { where :frickinawesome => true }, :class_name => "Bulb"
7

8
  has_one :bulb
9
  has_one :frickinawesome_bulb, -> { where :frickinawesome => true }, :class_name => "Bulb"
10

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

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

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

20
end
21 22

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

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