Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 26th, 2012  |  syntax: None  |  size: 0.22 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Rails: List of categories where related items count is greater than 0
  2. @categories = Category.where(category.items.count > 0).all
  3.        
  4. Category.joins(:items).select('distinct categories.*')
  5.        
  6. Items.find(:all).categories.uniq