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 ...