I have the following classes with associations:
class Customer < ActiveRecord::Base
has_many :orders
has_many :tickets, :through => :orders
has_many :technicians, :through => :ticket
has_many :services, :through => :ticket
end
class Order < ActiveRecord::Base
belongs_to :customer
has_many :tickets
has_many :technicians, :through => :tickets
has_many :services, :through => :tickets
end
class Service < ActiveRecord::Base
has_many :tickets
has_many :technicians, :through => :tickets
has_many :orders, :through => :tickets
end
class Technician < ActiveRecord::Base
has_many :tickets, :order => 'created_at DESC'
has_many :services, :through => :tickets
has_many :orders, :through => :tickets
end
class Ticket < ActiveRecord::Base
belongs_to :technician
belongs_to :service
belongs_to :order
end
I can do:
technician.tickets.service.price
But I can't do:
customer.orders.technician.name
customer.orders.last.tickets.technician.name
How do I go from customer to technician or service?