2016-11-21 4 views
0

一部のレコードをカテゴリ別にグループ化し、エイリアス列に基づいてすべての個別/固有レコードを選択しようとしています。ここまで私が持っているが、それは動作していない - それはまだ別個のレコードをもたらしません。レコードをグループ化し、列に基づいて別のレコードを選択する方法

Location.where("calendar_account_id = ?", current_user.calendar_accounts.first).group(:id,:alias).order("alias ASC").distinct.group_by(&:category) 

私はここで間違っていますか?

答えて

0

Location.select("DISTINCT(alias), *").where("calendar_account_id = ?", current_user.calendar_accounts.first).order("alias ASC").group_by(&:category) 

または

Location.where("calendar_account_id = ?", current_user.calendar_accounts.first).group(:alias).order("alias ASC").group_by(&:category) 
、これを試してみてください
関連する問題