views:

117

answers:

1

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

+1  A: 

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

zetetic