【发布时间】:2010-08-31 17:15:45
【问题描述】:
所以我有这些关系:
地点:
has_many :services
has_many :products, :through => :services
产品:
has_many :services
has_many :locations, :through => :services
has_many :add_ons
还有一项服务:
belongs_to :product
belongs_to :location
has_many :service_add_ons
has_many :add_ons, :through => :service_add_ons
一个 service_add_on:
belongs_to :service
belongs_to :add_on
我如何编写一个 :through 来返回一个包含其产品和每个产品附加组件的位置? 到目前为止我有:
wants.json { render :json => @location.to_json(:include => {:products => {:add_ons}}) }
这显然是行不通的。我可以做些什么来改变它并让它发挥作用?
【问题讨论】:
-
has_many :services has_many :locations, :through => :services has_many :add_ons... 我将其添加到问题中
标签: mysql ruby-on-rails join