Hello,
I''m having some problems with using acts_as_list with a scope. After
trying it out using an example from _Agile Web Development with Rails_
(starting on page 243 for those of you that have a copy), I modified
the example to fit my needs more closely.
I have the need for the parent table to have much more data than just
an id. This is the parent schema I''m using:
create table quotes (
id int not null auto_increment,
ref_number int not null,
created_on date,
updated_on date,
first_name varchar(255),
last_name varchar(255),
email varchar(255),
fax varchar(255),
phone varchar(255),
status int(1) default 0,
entered_by int,
notes varchar(255),
message text,
primary key (id)
);
And the child schema:
create table parts (
id int not null auto_increment,
quote_id int not null,
part_number varchar(255),
quantity int,
cost float,
description varchar(255),
position int,
constraint fk_quote foreign key (quote_id) references quotes(id),
primary key (id)
);
I have my models defined as such:
class Part < ActiveRecord::Base
belongs_to :quote
acts_as_list :scope => :quote_id
end
class Quote < ActiveRecord::Base
has_many :parts, :order => :position
end
So, I go into the console, and do the following:>> quote = Quote.new
=> #<Quote:0x25b6f20 @new_record=true,
@attributes={"message"=>nil,
"status"=>0, "created_on"=>nil,
"updated_on"=>nil, "notes"=>nil,
"phone"=>nil, "fax"=>nil,
"first_name"=>nil, "entered_by"=>nil,
"last_name"=>nil, "email"=>nil,
"ref_number"=>0}>>> quote.parts.create(:part_number => "A93", :quantity =>
1, :cost =>
10.95, :description => "test")
=> #<Part:0x257c6f4 @new_record=true,
@attributes={"quote_id"=>0,
"cost"=>10.95, "quantity"=>1,
"description"=>"test", "position"=>nil,
"part_number"=>"A93"}>>> quote.save
ActiveRecord::StatementInvalid: #42000You have an error in your SQL
syntax; check the manual that corresponds to your MySQL server version
for the right syntax to use near '''' at line 1: INSERT INTO
parts
(`quote_id`, `cost`, `quantity`, `description`, `position`,
`part_number`) VALUES(#<Quote:0x2554848>, #<Quote:0x255197c>,
#<Quote:0x254eab0>, #<Quote:0x254bbe4>, #<Quote:0x2548d18>,
#<Quote:0x2545e4c>)
Has anyone got any suggestions as to what I might be doing wrong? Any
help or suggestions would be appreciated.
Thanks, --ben