2017-07-09 13:41:28 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2010-06-27 11:17:44 -04:00
|
|
|
class Car < ActiveRecord::Base
|
2010-08-12 21:37:48 -04:00
|
|
|
has_many :bulbs
|
2020-04-12 01:17:32 -04:00
|
|
|
has_many :all_bulbs, -> { unscope(where: :name) }, class_name: "Bulb"
|
|
|
|
has_many :all_bulbs2, -> { unscope(:where) }, class_name: "Bulb"
|
|
|
|
has_many :other_bulbs, -> { unscope(where: :name).where(name: "other") }, class_name: "Bulb"
|
|
|
|
has_many :old_bulbs, -> { rewhere(name: "old") }, class_name: "Bulb"
|
2016-08-06 12:26:20 -04:00
|
|
|
has_many :funky_bulbs, class_name: "FunkyBulb", dependent: :destroy
|
|
|
|
has_many :failed_bulbs, class_name: "FailedBulb", dependent: :destroy
|
2016-08-06 13:37:57 -04:00
|
|
|
has_many :foo_bulbs, -> { where(name: "foo") }, class_name: "Bulb"
|
2015-11-15 09:56:52 -05:00
|
|
|
has_many :awesome_bulbs, -> { awesome }, class_name: "Bulb"
|
2011-05-10 18:35:01 -04:00
|
|
|
|
2011-05-12 18:29:07 -04:00
|
|
|
has_one :bulb
|
|
|
|
|
2010-08-03 17:26:59 -04:00
|
|
|
has_many :tyres
|
2016-08-06 13:37:57 -04:00
|
|
|
has_many :engines, dependent: :destroy, inverse_of: :my_car
|
|
|
|
has_many :wheels, as: :wheelable, dependent: :destroy
|
2010-08-03 17:26:59 -04:00
|
|
|
|
2016-08-06 13:37:57 -04:00
|
|
|
has_many :price_estimates, as: :estimate_of
|
2015-11-21 04:58:17 -05:00
|
|
|
|
2012-03-21 18:18:18 -04:00
|
|
|
scope :incl_tyres, -> { includes(:tyres) }
|
|
|
|
scope :incl_engines, -> { includes(:engines) }
|
2010-08-03 17:26:59 -04:00
|
|
|
|
2016-08-06 12:26:20 -04:00
|
|
|
scope :order_using_new_style, -> { order("name asc") }
|
2018-06-09 04:30:00 -04:00
|
|
|
|
|
|
|
attribute :wheels_owned_at, :datetime, default: -> { Time.now }
|
2010-06-27 11:17:44 -04:00
|
|
|
end
|
2010-09-07 13:08:03 -04:00
|
|
|
|
|
|
|
class CoolCar < Car
|
2016-08-06 12:26:20 -04:00
|
|
|
default_scope { order("name desc") }
|
2010-09-07 13:08:03 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
class FastCar < Car
|
2016-08-06 12:26:20 -04:00
|
|
|
default_scope { order("name desc") }
|
2010-09-07 13:08:03 -04:00
|
|
|
end
|