Ruby on rails 什么';让Rails 3/Active Record与简单销售点计划的课程建立关联的最佳方法是什么?

Ruby on rails 什么';让Rails 3/Active Record与简单销售点计划的课程建立关联的最佳方法是什么?,ruby-on-rails,activerecord,ruby-on-rails-3,Ruby On Rails,Activerecord,Ruby On Rails 3,我有5门课程是销售点计划的一部分: 客户、技术人员、订单、票据、服务 每个订单有一个客户和多张票。每张票上都有技术人员和许多服务 我应该如何进行关联,以便执行以下查找: customer.order.find by_date(2010年10月20日)。service.technology.name 这就是我的计划: class Customer < ActiveRecord::Base has_many :orders has_many :tickets, :through =

我有5门课程是销售点计划的一部分:
客户、技术人员、订单、票据、服务

每个订单有一个客户和多张票。每张票上都有技术人员和许多服务

我应该如何进行关联,以便执行以下查找:
customer.order.find by_date(2010年10月20日)。service.technology.name

这就是我的计划:

class Customer < ActiveRecord::Base  
  has_many :orders
  has_many :tickets, :through => :orders
  has_many :technicians, :through => :tickets
end  

class Technician < ActiveRecord::Base
  belongs_to :ticket
  belongs_to :service
end  

class Service < ActiveRecord::Base
  has_many :technicians  
  belongs_to :ticket
end  

class Ticket < ActiveRecord::Base
  has_many :services
  has_many :technicians, :through => :services      
end  

class Order < ActiveRecord::Base
  has_many :tickets
  has_many :services, :through => tickets
  has_many :technicians, :through => services

  belongs_to :customer
end 
class客户:订单
有很多:技术人员,:到=>:票
终止
类技师:服务
终止
类顺序票
有许多:技术人员,:通过=>服务
属于:客户
终止

客户和订单之间的关系是一对多的关系。订单和服务之间的关系也是一对多的。因此,您不能:

customer.order.find_by_date('10/20/2010').service.technician.name
应该是:

customer.orders.find_by_date('10/20/2010').services.each do |service|
  service.technician.name
end

这是一个与您的类似的问题。

客户和订单之间的关系是一对多的关系。订单和服务之间的关系也是一对多的。因此,您不能:

customer.order.find_by_date('10/20/2010').service.technician.name
应该是:

customer.orders.find_by_date('10/20/2010').services.each do |service|
  service.technician.name
end

这是一个与您的类似的问题。

使用当前布局,您将无法进行查找,因为服务有许多技术人员。这应该是一名技师,还是可能有多名技师从事一项服务?多名技师可以执行相同的服务;但是,每张票证只有一名技术人员执行一项或多项服务。按照当前布局,您将无法进行查找,因为服务中有许多技术人员。这应该是一名技师,还是可能有多名技师从事一项服务?多名技师可以执行相同的服务;但是,每张票据只有一名技师执行一项或多项服务。