簡體   English   中英

如何獲取屬於用戶的所有記錄並僅顯示具有不同名稱的記錄?

[英]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)

此查詢似乎不起作用。 它仍然僅獲取屬於該用戶的所有記錄。

您可以使用group by SQL查詢。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM