Reputation: 205
I'm using rails 2.3.4, rubygems 1.8.24, mac os x lion and ruby 1.9.3
I'm trying to render xml to an object called invoice. Now, i associated invoice with invoice_detail, so in my render :xml i wrote:
format.xml { render :xml => @invoice.to_xml(:include => :invoice_detail) }
but an error occurs: ActiveRecord::StatementInvalid Invalid column name 'invoice_id'
i have no invoice_id column in my db, and now i want rails to understand that. I want it to look at the inventoryDocId column instead of looking for an invoice_id column that doesn't exist. How do i do that? Thank you very much.
Upvotes: 0
Views: 356
Reputation: 6660
When you created your model invoice_detail you have to specify the foreign key column :
class InvoiceDetail < ActiveRecord::Base
belongs_to :invoice, :foreign_key => "inventoryDocId"
end
You have belongs_to options here : http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#method-i-belongs_to
Upvotes: 1