gpt4 book ai didi

mysql - Rails 4 中 'users' 中的未知列 'where clause'

转载 作者:行者123 更新时间:2023-11-29 00:03:00 25 4
gpt4 key购买 nike

如何修复这个错误。我正在使用 Rails 4

Mysql2::Error at /projects/aof_southwest

Unknown column 'users' in 'where clause'

在我的 projects_controller.rb 中

    def show
if params[:jump]
# try to redirect to the requested menu item
redirect_to_project_menu_item(@project, params[:jump]) && return
end

@users_by_role = @project.users_by_role
@subprojects = @project.children.visible.all
@news = @project.news.includes(:author, :project).order("#{News.table_name}.created_on DESC").limit(5)
@trackers = @project.rolled_up_trackers
end

# Returns a hash of project users grouped by role
def users_by_role
members.includes(:user, :roles).inject({}) do |h, m|
m.roles.each do |r|
h[r] ||= []
h[r] << m.user
end
h
end
end

项目.rb

has_many :members, -> { where("#{User.table_name}.type='User' AND #{User.table_name}.status=#{User::STATUS_ACTIVE}").includes(:principal, :roles)}

该列存在于 Mysql 中。但是我得到了

Mysql2::Error: Unknown column 'users' in 'where clause': SELECT `members`.* FROM `members` WHERE `members`.`project_id` = 117 AND (users AND users.status=1)

请帮我修正错误。

感谢您的帮助!

最佳答案

 Unknown column 'users' in 'where clause': SELECT `members`.* FROM `members` WHERE `members`.`project_id` = 117 AND (users AND users.status=1)

此错误表明您正在尝试搜索 USER 表中的成员:

尝试这样的事情:

Member.where(:type=> 'User',:status => "{User::STATUS_ACTIVE}").includes(:principal, :roles)

关于mysql - Rails 4 中 'users' 中的未知列 'where clause',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28848165/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com