2017-06-04 80 views
0

在Rails應用程序中,我有post模型和相對post_locations模型。我們使用searchkick來查找數據。當用戶輸入位置searchkick在location表中查找到那個位置時,那我怎麼知道id的位置。所以我需要的僅僅是在post_location已知的ID中搜索帖子。Searchkick,僅在特定ID中搜索

實施例:

用戶搜索芝加哥,在位置表芝加哥有id = 1。我需要在PostLocation.where(location_id: 1).posts.search 'other search params'中搜索。任何想法我怎麼能做到這一點?

回答

0

假設你想設置一個實例變量:

@post_location = PostLocation.search "*", where: { location_id: 1 } 

如果你有多個變量,它們傳遞到散。

@post_location = PostLocation.search "*", where: { location_id: 1, state: 'NY' } 
+0

我能找到PostLocation只是這樣做'PostLocation.where(LOCATION_ID:1)',也沒有必要爲搜索踢,但我想在'POST'程序搜索特定'PostLocation '後ID號。這很難解釋。 –