# Nuube Sequence problem

**URL:** <https://www.ruby-forum.com/t/nuube-sequence-problem/55490>\
**Category:** Rails\
**Created:** [March 21, 2006, 5:36pm UTC](https://www.ruby-forum.com/t/nuube-sequence-problem/55490 "2006-03-21T17:36:55Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![chris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/958977/32.png) [@chris](https://www.ruby-forum.com/u/chris)\
**Post date:** [March 21, 2006, 5:36pm UTC](https://www.ruby-forum.com/t/nuube-sequence-problem/55490/1 "2006-03-21T17:36:55Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![chris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/958977/32.png) [@chris](https://www.ruby-forum.com/u/chris)\
**Post date:** [March 21, 2006, 5:43pm UTC](https://www.ruby-forum.com/t/nuube-sequence-problem/55490/2 "2006-03-21T17:43:24Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![chris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/958977/32.png) [@chris](https://www.ruby-forum.com/u/chris)\
**Post date:** [March 21, 2006, 5:51pm UTC](https://www.ruby-forum.com/t/nuube-sequence-problem/55490/3 "2006-03-21T17:51:43Z")

</div>

Chris wrote:

> This is what i have done to solve it, but it is totally wrong/stupid:  
> Notice “@person.id+=1”  
>   
> 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?

---

<div class="post-metadata">

**Author:** ![chris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/958977/32.png) [@chris](https://www.ruby-forum.com/u/chris)\
**Post date:** [March 21, 2006, 5:56pm UTC](https://www.ruby-forum.com/t/nuube-sequence-problem/55490/4 "2006-03-21T17:56:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![chris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/958977/32.png) [@chris](https://www.ruby-forum.com/u/chris)\
**Post date:** [March 21, 2006, 6:06pm UTC](https://www.ruby-forum.com/t/nuube-sequence-problem/55490/5 "2006-03-21T18:06:30Z")

</div>

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 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

---

<div class="post-metadata">

**Author:** ![chris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/958977/32.png) [@chris](https://www.ruby-forum.com/u/chris)\
**Post date:** [March 21, 2006, 6:01pm UTC](https://www.ruby-forum.com/t/nuube-sequence-problem/55490/6 "2006-03-21T18:01:24Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![chris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/958977/32.png) [@chris](https://www.ruby-forum.com/u/chris)\
**Post date:** [March 21, 2006, 6:12pm UTC](https://www.ruby-forum.com/t/nuube-sequence-problem/55490/7 "2006-03-21T18:12:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![chris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/958977/32.png) [@chris](https://www.ruby-forum.com/u/chris)\
**Post date:** [March 21, 2006, 6:23pm UTC](https://www.ruby-forum.com/t/nuube-sequence-problem/55490/8 "2006-03-21T18:23:53Z")

</div>

Thanks Corey,

I’m using a legacy DB and a trigger existed that grabbed the next value  
from the sequence. I never thought of that!!

Chris
