Last active
August 14, 2017 21:37
-
-
Save ianhenrysmith/fbf206117066be7244eb78a97dd00566 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| # mongoid query to get post counts by body type | |
| def body_types | |
| @body_types = PostType.all.distinct(:body_type).sort | |
| end | |
| def body_type_count(body_type) | |
| post_type_ids = PostType.where(body_type: body_type).distinct(:id) | |
| Post.where(:post_type_id.in => post_type_ids, :synced_to_gallery_date.ne => nil).count | |
| end | |
| def body_type_counts | |
| {}.tap { |result| body_types.map { |body_type| result[body_type] = body_type_count(body_type) } } | |
| end | |
| def print_counts | |
| body_type_counts.each do |body_type, count| | |
| puts "#{body_type.humanize}: #{count}" | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment