主要是find_by_sql后边的代码有问题,总是提示说参数个数错误,怎么整?

quarterIdThe = params[:quarterThe_id].to_s    #得到--本季度操作--对话框     
  department = params[:department_id]  #得到选择的部门名称 
  upThe,downThe = getUpTheDownThe(quarterIdThe) #这是我自己写的一个方法,没有错误 
   busiesses = Business.find_by_sql["SELECT d.name FROM  businesses AS b 
    JOIN employees AS e ON (b.employee_id = e.id) 
    JOIN departments AS d ON (e.department_id = d.id) 
    WHERE d.code = Department AND b.out_date <= UpThe AND b.out_date > DownThe ",{:Department => 'department',:UpThe=> 'upThe',:DownThe=> 'downThe'}] 
我用的rails,这是在控制里面写的代码,主要是find_by_sql后边的代码有问题,总是提示说参数个数错误,求各位帮忙解决,或者是在model中写这个方法的话代码应该怎样写

白猪掌柜的
浏览 109回答 2
2回答

蝴蝶刀刀

Business.find_by_sql["SELECT&nbsp;d.name&nbsp;FROM&nbsp;&nbsp;businesses&nbsp;AS&nbsp;b&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;JOIN&nbsp;employees&nbsp;AS&nbsp;e&nbsp;ON&nbsp;(b.employee_id&nbsp;=&nbsp;e.id)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;JOIN&nbsp;departments&nbsp;AS&nbsp;d&nbsp;ON&nbsp;(e.department_id&nbsp;=&nbsp;d.id)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;WHERE&nbsp;d.code&nbsp;=&nbsp;?&nbsp;AND&nbsp;b.out_date&nbsp;<=&nbsp;?&nbsp;AND&nbsp;b.out_date&nbsp;>&nbsp;?",&nbsp;department,&nbsp;upThe,&nbsp;downThe] &nbsp;&nbsp;

慕尼黑的夜晚无繁华

{:Department => 'department',:UpThe=> 'upThe',:DownThe=> 'downThe'}&nbsp;你怎么这样写。。&nbsp;api&nbsp;# You can use the same string replacement techniques as you can with ActiveRecord#find&nbsp;&nbsp; Post.find_by_sql ["SELECT title FROM posts WHERE author = ? AND created > ?", author_id, start_date]&nbsp;&nbsp; > [#<Post:0x36bff9c @attributes={"first_name"=>"The Cheap Man Buys Twice"}>, ...]
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

MySQL