[英]Rails 4: MySQL 2 error
我已經將項目升級到Rails 4,但是Mysql出現錯誤:
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
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 .
第ASC LIMIT 1' at line 1: SELECT
id ASC LIMIT 1' at line 1: SELECT
t_dest_boards中ASC LIMIT 1' at line 1: SELECT
.* FROM
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中執行此操作的正確方法是什么? 提前致謝!
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.