繁体   English   中英

Rails 4:MySQL 2错误

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM