2017-02-15 67 views
-1

我已經升級我的項目到Rails 4,但MySQL是有錯誤:軌道4:MySQL的2錯誤

Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '=> nil OR delete_by < 1)) ORDER BY t_dest_boards . ID ASC LIMIT 1' at line 1: SELECT t_dest_boards .* FROM t_dest_boards WHERE (m_section_id = 1 AND v_employee_id = '02001' AND registration_date = '2017-02-13' AND (delete_by => nil OR delete_by < 1)) ORDER BY t_dest_boards . ID ASC LIMIT 1

在這行代碼:

tdest_tmp = TDestBoard.where("m_section_id = ? AND v_employee_id = ? AND registration_date = ? AND (delete_by => nil OR delete_by < ?)", primary_section.m_section_id, params[:id], params[:tdaily_dates]["#{id}"], 1).first

可能是什麼的正確方法在Rails 4中這樣做?提前致謝!

+0

delete_by =>無delete_by <1'您可以仔細檢查這個條件的查詢和什麼是'nil'? –

回答

3

delete_by => nil可能是引發錯誤的代碼。如果你想檢查一個字段是否爲零,則在條件中使用'IS NULL'。所以更改您的代碼如下

tdest_tmp = TDestBoard.where("m_section_id = ? AND v_employee_id = ? AND registration_date = ? AND (delete_by IS NULL OR delete_by < ?)", primary_section.m_section_id, params[:id], params[:tdaily_dates]["#{id}"], 1).first 
tdest_tmp = TDestBoard.where("m_section_id = ? AND v_employee_id = ? AND registration_date = ? AND (delete_by IS NULL OR delete_by < ?)", primary_section.m_section_id, params[:id], params[:tdaily_dates]["#{id}"], 1).first 
+0

謝謝@jith!修復 – skyranch