我正在尝试做这样的事情:
filter_categorys = params[:filter_categorys]
companies = Company.where('id_category = (?)', filter_categorys).joins(:subsidiary).where('zone = Nuñez')
而且它不工作....
所以,我需要让我所有的公司都有一个 id_category 并且他们在“区域”内至少有一个子公司。
我想这不是办法......请帮助!:D
公司.rb:
class Company < ActiveRecord::Base
has_many :subsidiary, :foreign_key => :id_company
has_many :benefit, :foreign_key => :id_company
set_primary_key :id_company
self.table_name = 'tbl_companys'
end
子公司.rb:
class Subsidiary < ActiveRecord::Base
belongs_to :company
set_primary_key :id_subsidiary
self.table_name = 'tbl_subsidiaries'
end