2016-01-13 75 views
0

我不知道我在哪裏錯了。 '主'是所有工作的完整列表。然後我爲不同的door_manufacturer設置了三個過濾器。有些門票有parts_mfr,如果它與manufacturing_location相同,我需要提取。我很困惑。再次,我不知道我在這裏錯過了什麼。複雜的鋼軌查詢

session[:door_location] = params[:location] || session[:door_location] || 'MASTER' 


if session[:door_location] == 'MASTER' 
    @tickets = Ticket.where(active: true, 
          complete_in_shop: false, 
          manufacturing_location: session[:factory]). 
    order(calendar_date: :asc).order(:calendar_order). 
    limit(90) 
else 

    tickets_door_location = Ticket.where(active: true, complete_in_shop: false, 
      manufacturing_location: session[:factory]) 
    tickets_parts_location = Ticket.where(active: true, complete_in_shop: false, 
      parts_mfr: session[:door_location]) 
    @tickets = (tickets_door_location << tickets_parts_location). 
      order(calendar_date: :asc).order(:calendar_order). 
      limit(90) 
end 

回答

1

你應該可以,如果你有最最新的活動記錄要做到這一點,而不是:

tickets = Ticket.where(active: true, complete_in_shop: false) 
tickets = tickets.where(parts_mfr: session[:door_location]).or(tickets.where( 
      manufacturing_location: session[:factory])) 
@tickets = tickets.order(calendar_date: :asc).order(:calendar_order). 
      limit(90) 

我在一箇舊版本的Rails的,所以我還沒有一個有機會測試這個,但這裏有一些例子:https://github.com/rails/rails/blob/master/activerecord/test/cases/relation/or_test.rb