下面的查詢在某些情況下返回nil軌轉換的包括查詢,返回零到範圍拉姆達
scope :claim_one, where(" location_id IS NULL OR start_time IS NULL OR archived IS NULL ").includes(:instructor_assignments).where('instructor_assignments.user_id IS NULL')
我想查詢轉換成一個lambda函數,它由返回的零的護理查詢如下;
scope :claim, (lambda do |claim| where(" location_id IS NULL OR start_time IS NULL OR archived IS NULL ").includes(:instructor_assignments).where('instructor_assignments.user_id IS NULL', claim) unless claim.nil? end)
,因爲我不認爲它有正確的軌道語法
謝謝
你好下面的代碼。對不起,「照顧零」是什麼意思?你想避免ActiveRecord :: RecordNotFound錯誤,或者當查詢返回沒有結果時返回一個不同的值? – jpgeek 2013-04-05 15:59:00
還有一件事:是'聲明'你想傳遞給查詢的參數,還是你想將它綁定到你的查詢結果? – jpgeek 2013-04-05 16:10:07