mysql - Rails Active Record group or ignore duplicate results from query -
i have active record query returns list of tags search query. i'm rendering json use in tag search.
the issue query return multiple tags of same kind. there ignore multiples or group multiples?
here's query (sorry it's quite long one):
tag.joins("inner join taggings on taggings.tag_id = tags.id inner join posts on taggings.taggable_id = posts.id inner join buckets on posts.bucket_id = buckets.id inner join memberships on memberships.bucket_id = buckets.id").where(memberships: {user_id: current_user.id, accepted: true}).where("name ?" , "#{params[:query]}%")
for example, when search 'illustration' 2 posts tagged illustration returned , i'd group one:
thanks!
you should able chain .uniq
onto end of query bring unique records. or try .distinct
Comments
Post a Comment