Model Relation - has_and_belongs_to_many

Hello everyone
I am very much confused about specifying the relation in the following
one. I had Item, Invoice, Invoicedetail model.
Item table contains - id and name,unit_price fields.
Invoice table contains - id, invoice_number and date
Invoicedetails - invoice_id, item_id, quantity, unit_price fields.
I had mentioned the following relations.
class Item < ActiveRecord::Base
has_many :invoicedetails
has_many :invoices, :through=>:invoicedetails
class Invoicedetail < ActiveRecord::Base
belongs_to :item
belongs_to :invoice
class Invoice < ActiveRecord::Base
has_many :invoicedetails
has_many :items, :through=>:invoicedetails
May anyone suggest I am specifying the correct relation or not? If it is
wrong please give correct one and suggestions for understanding the
specification of relations more.
Thanks in advance

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs