2016-10-03 112 views
1

我對軌道仍然很陌生,試圖弄清楚這一點。在另一個活動記錄上過濾活動記錄

我有幾個型號:

約會= belongs_to的廠商 廠商HAS_MANY通過vendor_locations

我基於區域位置過濾一些地圖標記位置:

if params[:search].present? 
     location_ids = Location.near(params[:search], 50, order: '').pluck(:id) 
     @vendor_locations = VendorLocation.includes(:location).where(location_id: location_ids) 
    else 
     location_ids = Location.near([session[:latitude], session[:longitude]], 50, order: '').pluck(:id) 
     @vendor_locations = VendorLocation.includes(:location).where(location_id: location_ids) 
    end 

我我試圖過濾那些與搜索區域中的供應商相關聯的活動APPOINTMENTS。

我試圖設置活動記錄與包括:

def index 
if params[:service].blank? 
    @appointments = Appointment.includes(:vendor).where(vendors: {id: @vendor_locations.vendor_id}) 

但那顯然不工作。有關如何基於@vendor_locations過濾的任何建議?

+0

現在定義工作。你有什麼錯誤嗎? – Pavan

回答

0

普呂克從vendor_locations VENDOR_ID過濾約會:

@vendor_locations = VendorLocation.where(location_id: location_ids) 
@appointments = Appointment. 
        includes(:vendor). 
        where vendor_id: @vendor_locations.select(:vendor_id) 
+0

這樣做!謝謝! –