Skip to content

Instantly share code, notes, and snippets.

@icleversoft
Created September 2, 2016 16:53
Show Gist options
  • Save icleversoft/2a7e6ee4723c238dc059f8b60b1eb5c1 to your computer and use it in GitHub Desktop.
Save icleversoft/2a7e6ee4723c238dc059f8b60b1eb5c1 to your computer and use it in GitHub Desktop.
another approach
tenant.invoices.joins(:line_items)
.includes(line_items:[:accounting])
.where('line_items.type=?', 'SimpleLineItem')
.where('line_items.description ilike ?', '%er%')
.map(&:line_items).flatten
.map(&:description)
.select{|x| x.match(/er/i)}
.sort{|a,b| a.downcase<=>b.downcase}
.uniq.first(5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment