Forum: Ruby on Rails Model Relation - has_and_belongs_to_many

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Indu R. (Guest)
on 2009-01-08 10:00
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 topic is locked and can not be replied to.