简体   繁体   中英

Association with Searchlogic

Hi I have a post model that :has_many :reply, when using searchlogic, doing Post.reply_content_like("search"), returns a result for every reply under that post, I only want it to return once. Anyone know a way to solve this

Searchlogic returns an array of Posts matching your criteria, just as if you used an ActiveRecord find . If you only want to get one result, well, which one? The first? The last?

If you want to get the unique, matched column values, you could do

Post.reply_content_like("search").collect(&:reply_content).uniq

or if you just want the first Post

Post.reply_content_like("search").first

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM