简体   繁体   中英

How do I fetch all records which belong to a user and show only the records with distinct name?

Tagmap.where(user_id: current_user.id).uniq(:name)

This query doesn't seem to work. It still fetches all the records belonging to that user only.

您可以使用group by SQL查询。

Tagmap.where(user_id: current_user.id).group(:name)

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