hi all,
i am trying a little project based on the agile book’s shopping cart
example and have hit a problem. the inserts are failing when saving a
quote which contains line_items. the models are as follows
(quote_line_item is using single table inheritance):
class Quote < ActiveRecord::Base
has_many :quote_line_items
end
class LineItem < ActiveRecord::Base
end
class QuoteLineItem < LineItem
belongs_to :quote
belongs_to :product
end
the section of code that actually fails is here (labelled)
def send_quote
@quote = Quote.new(params[:quote])
@quote.quote_line_items << @cart.items
if @quote.save # <---- error occurs here
@cart.empty!
redirect_to_index(‘Thanks for requesting a quote. We will be in
contact with you shortly’)
else
redirect_to :action => ‘details’
end
end
it fails with the following (note the values to be inserted are actually
objects that have not been dereferenced:
INSERT INTO line_items (order_id
, quote_id
, updated_at
,
created_by
, product_id
, quantity
, type
, updated_by
,
unit_price
, created_at
) VALUES(#Quote:0xa75703d0,
#Quote:0xa75738a0, #Quote:0xa75749a8, #Quote:0xa756b268,
#Quote:0xa7561218, #Quote:0xa75632fc, #Quote:0xa7567b18,
#Quote:0xa755ef40, #Quote:0xa7559fcc, #Quote:0xa7553654)
i have debugged the code and immediately before the save the objects
@quote and @cart are correct and without errors. it is a little
confusing. without STI it seems to work fine. i have never received
errors like this before although i have not used STI before.
any suggestions would be greatly appreciated.
-felix