Skip to content

Instantly share code, notes, and snippets.

@naru
Created January 13, 2011 19:49
Show Gist options
  • Save naru/778467 to your computer and use it in GitHub Desktop.
Save naru/778467 to your computer and use it in GitHub Desktop.
# quantity isn't an attribute of the current model, so it doesn't show up in results
named_scope :distinct_for_invoice, lambda {|ids| {
:select => 'count(id) as quantity, product_id, net_price_in_cents',
:conditions => ["id IN (?)", ids],
:group => 'product_id, net_price_in_cents'
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment