Tuesday, May 4, 2010

Finding uninvoiced fees in rails


# Models

Class InvoiceItem < ActiveRecord::Base
  belongs_to :fee
end

Class Fee < ActiveRecord::Base
  has_one :invoice_item
end

# Namedcope in Fee model

namedscope :uninvoiced, {
  :conditions => "fees.id NOT IN (SELECT fee_id FROM invoice_items)"
}

No comments: