Skip to content

Instantly share code, notes, and snippets.

@stevenbristol
Created April 17, 2012 15:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save stevenbristol/2406727 to your computer and use it in GitHub Desktop.
Save stevenbristol/2406727 to your computer and use it in GitHub Desktop.
class Business
many :invoices
end
class Invoice
property :ref, String
property :total, BigDecimal
property :paid_total, BigDecimal
one :buinsess
index [:business, :ref] #key like "#{business_key}_invoices_#{ref}}"
index [:business, :paid], :if => ->{|me| me.paid_total >= me.total} #key like "#{business_key}_invoices_paid"
index [:business, :unpaid], :if => ->{|me| me.paid_total < me.total} #key like "#{business_key}_invoices_unpaid"
end
b = business.find(1)
b.invoices.count # 3
b.invoices.paid.count #2
b.invoices.unpaid.count #1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment