【发布时间】:2019-11-10 09:20:09
【问题描述】:
我正在尝试获取所有不属于当前用户的卡片,并且它的标题包含一些关键字。
经过研究,我目前得到的是下面的这段代码。
@other_cards = Card.where(:user_id.ne => @temp_current_user, "title LIKE ?" => "%Business%").limit(10).order('created_at desc down_title asc')
但即使存在记录,也不会返回任何记录。
我还尝试跳过 :user_id 条件以及所有限制和订单,从而生成了这个简单的代码来检查它是否会返回任何内容
@other_cards = Card.where("title LIKE ?", "%Business%")
编辑
我也尝试将条件作为第一个评论中建议的数组。也导致了错误
编辑 2
附上在rails控制台中运行查询的截图
【问题讨论】:
-
请更新您的 Rails 版本。
Card.where("title LIKE ?", "%Business%")应该可以工作 -
请在 Rails 控制台中尝试相同的查询并将其结果查询和输出粘贴到此处。
-
@other_cards = Card.where("user_id = ? AND title LIKE ?", @temp_current_user.id, "%Business%").limit(10).order('created_at desc down_title asc')请检查此查询 -
@A.A.F 试试这个
Card.find({"title": /.*Business.*/})
标签: ruby-on-rails mongoid