[英]Rails + Sunspot: Multiple model search, but only certain fields on one of the models?
[英]How to identify models in sunspot multiple model search?
我想搜索商店,圖表和最后一個模型。
為了時間和坐標,我將ID放入會話中。
我想將ID用於其他目的。
有什么方法可以識別id的源模型?
@searchs = Sunspot.search store, chart, last do |s|
s.fulltext params[:search]
s.with(:end_at).greater_than(Time.now)
end.results
ar=[]
@searchs.each do |a|
if a.coordinate_x.nil? || a.coordinate_y.nil?
next
end
ar << a.id
end
session[:stores_id] = ar
您必須存儲更多信息才能識別源模型。 遍歷結果時,可以獲取並存儲類的名稱。 根據此信息,您可以確定正在檢查類型的源模型。
@searchs = Sunspot.search store, chart, last do |s|
s.fulltext params[:search]
s.with(:end_at).greater_than(Time.now)
end.results
ar=[]
@searchs.each do |a|
if a.coordinate_x.nil? || a.coordinate_y.nil?
next
end
# Store the type of the item and its id.
ar << {type: a.class.name, id: a.id}
end
session[:stores_id] = ar
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.