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中写这个方法的话代码应该怎样写
2 回答
蝴蝶刀刀
TA贡献1801条经验 获得超8个赞
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 = ? AND b.out_date <= ? AND b.out_date > ?", department, upThe, downThe]
慕尼黑的夜晚无繁华
TA贡献1864条经验 获得超6个赞
{:Department => 'department',:UpThe=> 'upThe',:DownThe=> 'downThe'}
你怎么这样写。。
api
# You can use the same string replacement techniques as you can with ActiveRecord#find
Post.find_by_sql ["SELECT title FROM posts WHERE author = ? AND created > ?", author_id, start_date]
> [#<Post:0x36bff9c @attributes={"first_name"=>"The Cheap Man Buys Twice"}>, ...]
添加回答
举报
0/150
提交
取消