In my database the id for a field is 810. RoR thinks that it is 809. My log file (below) shows that just before the insert it grabs the next sequence value. I dont think it should do that. This causes problems further down the line when trying to access the Person object. Development Log file : "SQL (0.016000) select people_seq.nextval id from dual Person Create (0.015000) INSERT INTO people (title, weight, mothers_maiden_name, shoe_size, middlename, person_type, username, firstname, height, person_id, createdby, expired, name_string, surname) VALUES(''Mr'', ''100'', '''', 10, ''T'', null, null, ''T'', '''', :id, ''Chris Richards'', 0, null, ''T'')" My Code (standard generated code): def create_person @person = Person.new(params[:person]) if @person.save flash[:notice] = ''Person was successfully created.'' ..... else ...... end end Its wierd, ive used rails for weeks with no problems. Any ideas? -- Posted via http://www.ruby-forum.com/.
This is what i have done to solve it, but it is totally wrong/stupid: Notice "@person.id+=1" if @person.save @person.id+=1 #!!!!! flash[:notice] = ''Person was successfully created.'' ... else ... end This makes me feel dirty!! anyone any ideas wtf is going on? -- Posted via http://www.ruby-forum.com/.
Chris wrote:> This is what i have done to solve it, but it is totally wrong/stupid: > Notice "@person.id+=1"<snip>> This makes me feel dirty!! anyone any ideas wtf is going on?Which DB are you using, and why do you think the database has a different idea about the value of an ID to Rails? -- Alex
I''m using Oracle. I get this error when i try to use the person object: "Couldn''t find Person with ID=825.0" It actually has an id of 826 in the DB. Strange. Thanks, Chris -- Posted via http://www.ruby-forum.com/.
Chris wrote:> I''m using Oracle. > > I get this error when i try to use the person object: > > "Couldn''t find Person with ID=825.0" > > It actually has an id of 826 in the DB. Strange. >Not an Oracle user myself, so I can''t help that much, but it might be worth checking the column type of the id field. Other than that, not sure. -- Alex
Hi Chris, I?ve done some tests with Oracle and it worked perfectly well. I did only a small trick to avoid getting that decimal point on the ID: on the view we use :id => doc.id.round. []?s 2006/3/21, Chris <evilgeenius@gmail.com>:> I''m using Oracle. > > I get this error when i try to use the person object: > > "Couldn''t find Person with ID=825.0" > > It actually has an id of 826 in the DB. Strange. > > Thanks, > Chris > > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Do you have a trigger on the table that also fetches the ID from the sequence when you''re inserting records? If so, you might want to modify the trigger so that if the new ID is passed in, to use it, otherwise grab a value from the sequence, something like: create or modify trigger mytable_bi before insert on mytable for each row if :new.id is null then insert into mytable values (myseq.nextval, ...) else insert into mytable values (:new.id, ...) endif end On 3/21/06, Chris <evilgeenius@gmail.com> wrote:> I''m using Oracle. > > I get this error when i try to use the person object: > > "Couldn''t find Person with ID=825.0" > > It actually has an id of 826 in the DB. Strange. > > Thanks, > Chris > > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >