Skip to content

Instantly share code, notes, and snippets.

@jliang87
jliang87 / generate_report_rake_task.rb
Last active December 29, 2015 18:29
bundle exec rake update_data:generate_report
desc "Generate report on categories and save to CSV file"
task :generate_report => :environment do
results = []
companies = Company.joins("INNER JOIN banyan_categorizations ON banyan_categorizations.categorizable_id = companies.id AND banyan_categorizations.categorizable_type = 'Company'")
.joins("INNER JOIN banyan_categories on banyan_categorizations.category_id = banyan_categories.id")
.where("banyan_categories.tag = 'GPN Partner Agent'")
.group('companies.id').map{|x| {id: x.id, name: x.name}}
group_ids = [{id: CommunitySection.find_by_name("Cisco").organization_types.partner.first.category_groups.where(tag: 'certification_classification').first.id, name: "certification_classification"},
{id: CommunitySection.find_by_name("Cisco").organization_types.partner.first.category_groups.where(tag: 'authorized_technology_partner').first.id, name: "authorized_technology_partner"},