Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 在Rails 3.2.11中为多个联接抛出不明确错误_Ruby On Rails - Fatal编程技术网

Ruby on rails 在Rails 3.2.11中为多个联接抛出不明确错误

Ruby on rails 在Rails 3.2.11中为多个联接抛出不明确错误,ruby-on-rails,Ruby On Rails,我有一个问题: User.select("distinct username as value, username as foto, roles.user_id as ID, followers as follower "). where("username ILIKE ?", "%#{params[:term]}%"). joins(:identities).joins(:roles).all(conditions:{roles:{name: 'Creator'}}) 但是user\u i

我有一个问题:

User.select("distinct username as value, username as foto, roles.user_id as ID, 
followers as follower ").
where("username ILIKE ?", "%#{params[:term]}%").
joins(:identities).joins(:roles).all(conditions:{roles:{name: 'Creator'}})
但是
user\u id
得到了一个错误,因为我假设
identifications
表也在使用它

我如何实际指定
user\u id
列仅用于查询
角色

任何变通办法都将受到赞赏

编辑:

日志:


您应该能够使用
users.id
roles\u users.user\u id

User.select("distinct username as value, username as foto, users.id as ID ...

这发生在我的模型上有默认订单时。你能发布正在执行的确切查询吗?您可以在日志中找到它。@musicnerd47或者您可以简单地将
.to\u sql
添加到上面的代码中,然后在控制台中运行它。@BroiSatse!我从来没见过。@xirukitepe,你能粘贴准确的错误消息吗?您的代码确实指定了哪个表user_id处于打开状态,所以这不应该是问题所在。哪些用户、身份或角色表有“username”列?更重要的是,它只在其中一个表上定义吗?我编辑了这篇博文。救了我的命。很长一段时间以来,我一直在和不同的桌子打交道。
User.select("distinct username as value, username as foto, users.id as ID ...