Rails - 如何分隔保留的sql关键字

时间:2016-09-21 14:43:48

标签: sql ruby-on-rails

我正在开发一个在其他应用/部分中运行的排序例程。但是,似乎生成的查询不起作用,因为关联的表名为user,显然是一个保留的SQL字。修复方法是让查询引用'[user] .name'而不是user.name

导致问题的一行是

   @workflows = @workflows.includes(:user).order(params[:sort] + ' ' + params[:direction])

我得到的错误是

ActiveRecord::StatementInvalid in Workflows#index
Showing C:/Users/cmendla/RubymineProjects/product_development/app/views/workflows/index.html.erb where line #14 raised:

TinyTds::Error: Cannot call methods on nvarchar.: EXEC sp_executesql N'SELECT [pd].[workflows].[id] AS t0_r0, [pd].[workflows].[title] AS t0_r1, [pd].[workflows].[user_id] AS t0_r2, [pd].[workflows].[created_at] AS t0_r3, [pd].[workflows].[updated_at] AS t0_r4, [pd].[users].[id] AS t1_r0, [pd].[users].[login] AS t1_r1, [pd].[users].[group_strings] AS t1_r2, [pd].[users].[name] AS t1_r3, [pd].[users].[ou_strings] AS t1_r4, [pd].[users].[email] AS t1_r5, [pd].[users].[created_at] AS t1_r6, [pd].[users].[updated_at] AS t1_r7 FROM [pd].[workflows] LEFT OUTER JOIN [pd].[users] ON [pd].[users].[id] = [pd].[workflows].[user_id]  ORDER BY user.name asc'
Rails.root: C:/Users/cmendla/RubymineProjects/product_development

Application Trace | Framework Trace | Full Trace
app/views/workflows/index.html.erb:14:in `_app_views_workflows_index_html_erb__557116297_91831440'
Request

网址看起来像http://localhost:3000/workflows?direction=asc&sort=user.name

我可以修改@workflows =行,以便将用户放在[]中吗?

0 个答案:

没有答案