Invoice item is a model in our rails 3.2.8 app. Its definition is:
class InvoiceItem < ActiveRecord::Base
belongs_to :invoice
belongs_to :quote_test_item, :class_name => 'QuoteTestItem'
belongs_to :lease_usage_record, :class_name => 'LeaseUsageRecord'
validates :lease_usage_record_id, :uniqueness => { :scope => :invoice_id }, :unless => "lease_usage_record_id.nil?"
end
There are 3 associations. If i is an invoice item object. i.quote_test_item will create error (in rails console):
irb(main):037:0> i.quote_test_item
NameError: uninitialized constant InvoiceItem::quote_test_item
i is:
irb(main):038:0> i
=> #<InvoiceItem id: 6, invoice_id: 6, lease_usage_record_id: nil, created_at: "2012-07-25 19:28:37", updated_at: "2012-07-25 19:28:37", quote_test_item_id: 1>
But both i.invoice and i.lease_usage_record went through and did not create any error. For example:
irb(main):036:0> i.lease_usage_record
=> nil
Why only i.quote_test_item created error? Thanks so much.
Make sure you have performed all migrations. You might also want to check whether your
QuoteTestItem(which by the way, you don’t have to specify the:classnamesince its inferred) to check whether you have a correspondinghas_one :invoice_itemorhas_many :invoice_items, depending on how your modelling it.