class Entity < ActiveRecord::Base
include Tire::Model::Search
include Tire::Model::Callbacks
has_many :reports,:dependent=>:destroy
def self.search(params)
tire.search() do
query { string params[:query] } if params[:query].present?
end
end
def to_indexed_json
to_json(:include => [:reports])
end
end
class Report < ActiveRecord::Base
belongs_to :entity
has_many :schedules,:dependent=>:destroy
end
我是“elasticsearch”的新手。我可以通过上面的代码搜索“报告”。但是我如何包含“时间表”以便我可以在实体模型中搜索其数据。请帮助我。
答案 0 :(得分:1)
在Entity
has_many :reports,:dependent=>:destroy
模型中
has_many :schedules, :through => :reports
确保belongs_to :report
模型中有Schedule
。