1

G'day guys, trying to build a small invoicing system (that can generate PDF's using prawn), but am having an issue with generating multiples of indivdual items in the array. I have the Invoice class which has_many :items, but when I try to add a multiple of an item to the invoice, it won't actually add that to the invoice and it doesn't update the total.

Would I be better using a line_item model abstraction that has a has_one to the item but an integer that keeps the multiples of the item in the invoice?

1 Answer 1

3

It sounds like you have a many-to-many relationship, an Item may be in many invoices (more than one time) and an Invoice has many items.

class Invoice < ActiveRecord::Base
  has_many :invoice_items
  has_many :items, :through => :invoice_items
end

class InvoiceItem < ActiveRecord::Base
  belongs_to :invoice
  belongs_to :item
end
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.