Advertisement
Guest User

Untitled

a guest
Dec 6th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. # Batch update counts for single categories (not recursive)
  2. Category.all.each{|cat|
  3. count_single = CategoryCompany.where(:category_id => cat.id).count
  4. puts "#{cat.id}: #{cat.name} ---- #{count_single}"
  5. cat.update_columns(company_count_single: count_single)
  6. # cat.company_count_single = count_single
  7. # cat.companies_count_bypass = true
  8. # cat.save
  9. }
  10.  
  11. # Batch update counts for companies with their children
  12. Category.all.each{|cat|
  13. count = CategoriesHelper.get_company_count(cat.id)
  14. cat.update_columns(company_count: count)
  15. # cat.company_count = count
  16. # cat.companies_count_bypass = true
  17. # cat.save
  18. }
  19.  
  20. # Delete categories that have zero companies (maybe)
  21. # Category.where(:company_count => 0).destroy_all
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement