Skip to content

Instantly share code, notes, and snippets.

@dsasse07
Created December 28, 2020 23:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dsasse07/84e2d1a813e73e29e34c4b486c766b70 to your computer and use it in GitHub Desktop.
Save dsasse07/84e2d1a813e73e29e34c4b486c766b70 to your computer and use it in GitHub Desktop.
ActiveRecord group by count
Rental.group(:vhs).count #=>
#{<Vhs:0x00007f8d5e2bf0f0 id: 17, serial_number: "MAX-luqovgdk8e7tl", movie_id: 9 => 1,
#<Vhs:0x00007f8d4f81a4a0 id: 29, serial_number: "BABA-t6k24krzqclts", movie_id: 13 =>2,
#<Vhs:0x00007f8d4f854538 id: 11, serial_number: "BABA-begvxe7ai0rc6", movie_id: 13 =>3}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment