Having issues saving line items to the DB

Hello everyone, I’m fairly new to Rails (writing my first real app) and
brand new to this mailing list.

I’ve got a rails/sql error I just can’t seem to solve. It’s probably
really simple, but I’m been googling and reading for a day and have made
zero progress on it. Hopefully someone on this list can shine some light
on my problem, or point me in the right direction.

Thanks!

Nick Ciske

Environment

Rails 1.1.3
Windows XP/WebBrick
SQL Server Express 2005

Code

Models:

Project
has_many :quotes

Quote
has_many :line_items

LineItem
belongs_to :quote

@project = Project.new(params[:project])
@quote=Quote.new(params[:quote])

@line_items=[]

if params[:line_item1][‘quantity_id’] != ‘’
@line_items << LineItem.new(params[:line_item1])
end

if params[:line_item2][‘quantity_id’] != ‘’
@line_items << LineItem.new(params[:line_item2])
end

@[email protected]
@quote.line_items << @line_items

@quote.save

Problem

I can get the project and quote models to save to the DB just fine, but
when I try to add the line_items array to the quote object (so they are
saved as child records) I get a nasty SQL error.

Rails appears to be trying to save the internal object reference to the
DB, instead of the attributes. I can’t figure out why, or how to fix it.

DBI::DatabaseError: Execute

OLE error code:80040E14 in Microsoft OLE DB Provider for SQL Server
The name “#” is not permitted in this context. Valid expressions are
constants, constant expressions, and (in some contexts) variables.
Column names are not permitted.

HRESULT error code:0x80020009

Exception occurred.: INSERT INTO line_items ([cost_total], [quote_id],
[text_pounds_order], [freight_weight], [quantity_id], [cost_overs],
[text_pounds_overs], [cost_each], [cost_freight])
VALUES(#Quote:0x355e998, #Quote:0x3552e18, #Quote:0x355b7a0,
#Quote:0x354ce30, #Quote:0x3549c38, #Quote:0x3546a58,
#Quote:0x3543878, #Quote:0x3540590, #Quote:0x353d3b0)

@quote.line_items << @line_items

I dont think you can append an array to an association like that. Try
this instead:

@line_items.each do |li|
@quote << li
end