Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Batch update counts for single categories (not recursive)
- Category.all.each{|cat|
- count_single = CategoryCompany.where(:category_id => cat.id).count
- puts "#{cat.id}: #{cat.name} ---- #{count_single}"
- cat.update_columns(company_count_single: count_single)
- # cat.company_count_single = count_single
- # cat.companies_count_bypass = true
- # cat.save
- }
- # Batch update counts for companies with their children
- Category.all.each{|cat|
- count = CategoriesHelper.get_company_count(cat.id)
- cat.update_columns(company_count: count)
- # cat.company_count = count
- # cat.companies_count_bypass = true
- # cat.save
- }
- # Delete categories that have zero companies (maybe)
- # Category.where(:company_count => 0).destroy_all
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement