Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
嗨,我有一个帖子模型:has_many:reply,在使用搜索逻辑时,执行 Post.reply_content_like("search"),为该帖子下的每个回复返回一个结果,我只希望它返回一次。任何人都知道解决这个问题的方法
Searchlogic 返回一个与您的条件匹配的 Posts 数组,就像您使用 ActiveRecord 一样find。如果你只想得到一个结果,那么,哪一个?首先?最后?
find
如果你想获得唯一的、匹配的列值,你可以这样做
Post.reply_content_like("search").collect(&:reply_content).uniq
或者如果你只想要第一个帖子
Post.reply_content_like("search").first