Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/64.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查询关联(连接)和#x27;富文本';不是零/空_Ruby On Rails_Ruby - Fatal编程技术网

Ruby on rails Rails查询关联(连接)和#x27;富文本';不是零/空

Ruby on rails Rails查询关联(连接)和#x27;富文本';不是零/空,ruby-on-rails,ruby,Ruby On Rails,Ruby,我现在有以下内容,可以成功地生成一个用户列表,其中包含他们的rich\u text\u tlk\u和\u me“rich\u text”附件 User.joins(:rich_text_tlk_with_me).paginate(page: params[:page], per_page: 5).order(created_at: :desc) 但是,目前此查询还显示了具有空富文本附件的用户 User.joins(:rich_text_tlk_with_me).paginate(page: p

我现在有以下内容,可以成功地生成一个用户列表,其中包含他们的
rich\u text\u tlk\u和\u me
“rich\u text”附件

User.joins(:rich_text_tlk_with_me).paginate(page: params[:page], per_page: 5).order(created_at: :desc)
但是,目前此查询还显示了具有空富文本附件的用户

User.joins(:rich_text_tlk_with_me).paginate(page: params[:page], per_page: 5).order(created_at: :desc)
我想运行一个查询,该查询只返回具有非空富文本附件的用户

我试过:

User.joins(:rich_text_tlk_with_me).where.not(rich_text_tlk_with_me: [nil, ""]).paginate(page: params[:page], per_page: 5).order(created_at: :desc)
但这并没有带来任何回报


我也搜索了文档,但没有找到任何相关的内容

假设
用户有很多:富文本和mes,并且您使用的是Rails版本>5

通过以下查询,您可以获取所有具有关联的
富文本\u tlk\u和\u me
用户

User.left_outer_joins(:rich_text_tlk_with_mes).where.not(rich_text_tlk_with_mes: {id: nil}).paginate(page: params[:page], per_page: 5).order(created_at: :desc)

感谢您的回答,我实际上意识到我的查询是成功的(oops!),但没有处理用户删除内容的情况。相反,我将添加一个“销毁附件”路由,这样不想被列出的用户就可以删除自己。谢谢你的帮助