Skip to content

Instantly share code, notes, and snippets.

@joegaudet
Last active November 28, 2019 00:10
Show Gist options
  • Save joegaudet/5064617d448682d4ab0f6997c3cf8d90 to your computer and use it in GitHub Desktop.
Save joegaudet/5064617d448682d4ab0f6997c3cf8d90 to your computer and use it in GitHub Desktop.
class Accounting::LedgerItem < ApplicationRecord
# super class
has_many :line_items, class_name: 'Accounting::LineItem', as: :ledger_item
# specific line items
has_many :ordered_items, class_name: 'Accounting::LineItems::OrderedItem', as: :ledger_item
has_many :fees, class_name: 'Accounting::LineItems::Fee', as: :ledger_item
has_many :payments, class_name: 'Accounting::LineItems::Payment', as: :ledger_item
has_many :discounts, class_name: 'Accounting::LineItems::Discount', as: :ledger_item
end
class Accounting::LineItem < ApplicationRecord
belongs_to :ledger_item, class_name: 'Accounting::LedgerItem'
end
class Accounting::LineItems::OrderedItem < Accounting::LineItem
end
class Accounting::LineItems::Discount < Accounting::LineItem
end
class Accounting::LineItems::Fee < Accounting::LineItem
end
class Accounting::LineItems::Payment < Accounting::LineItem
end
li = Accounting::LedgerItem.new
li.order_items.build()
li.line_items.must_equal 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment