Created
March 26, 2013 06:34
-
-
Save satoshin2071/5243543 to your computer and use it in GitHub Desktop.
ActiveRecordでgroup Byしてカウントをして、カウント数でorderする via 酒と泪とRubyとRailsと
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#===sample | |
# | |
#MP3プレイヤーのProductのmaker名をレコード数の多い順に並べてその結果のハッシュのkeyであるmaker名を配列として取得 | |
# | |
Product.where(category: "MP3 Player").group(:maker).order('count_maker desc').count('maker').keys |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment