你能帮我思考狮身人面像吗?思维狮身人面像有很多通过导轨
关系:
大陆 的has_many:国家 的has_many:country_reports,通过:国家:CLASS_NAME => “报告” 的has_many:出版者,通过:country_reports
预期输出:
我想找到Continent.first.publishers
请告诉我如何写在思维狮身人面像轨道
你能帮我思考狮身人面像吗?思维狮身人面像有很多通过导轨
关系:
大陆 的has_many:国家 的has_many:country_reports,通过:国家:CLASS_NAME => “报告” 的has_many:出版者,通过:country_reports
预期输出:
我想找到Continent.first.publishers
请告诉我如何写在思维狮身人面像轨道
正如我回答的思考狮身人面像谷歌组:
因为你在出版商搜索,这是你需要修改,以得到这个工作,发布指数。我假设发布者belongs_to:country_report,国家报告belongs_to:国家和国家belongs_to:大陆。
如果你使用SQL支持指数(使用:用=>:active_record选项),那么你会希望在你的发行指标如下:
has country_report.country.continent_id, :as => :continent_id
如果你使用真正的 - 时间指数(:用=>:REAL_TIME),那么它是相同的,但你必须指定类型,以及:
has country_report.country.continent_id, :as => :continent_id, :type => :integer
但是,如果在从链协会是一个的has_many或has_and_belongs_to_many代替belongs_to的的出版商到大陆,那么它有点复杂。此外,在这种情况下,发布商可能有多个大陆,因此我们在此处理多个值。
对于SQL支持指数,一个微小的变化,改变的关联链:
has country_reports.country.continent_id, :as => :continent_ids
但随着实时指数,最好是有一个返回所需的值在发布模型的方法或值,然后使用该索引:
# in app/models/publisher.rb
def continent_ids
country_reports.collect(&:country).collect(&:continent_id)
end
# in app/indices/publisher_index.rb
has continent_ids, :type => :integer, :multi => true
然后,一旦你重建索引,您可以搜索如下(与属性是多如适用):
Publisher.search “foo”, :with => {:continent_id => continent.id}
这可能工作,以及(关联的多层次,虽然可以混淆的东西):
continent.publishers.search “foo”