# Turn off auto increment

**URL:** <https://www.ruby-forum.com/t/turn-off-auto-increment/79248>\
**Category:** Rails\
**Created:** [March 9, 2006, 10:52pm UTC](https://www.ruby-forum.com/t/turn-off-auto-increment/79248 "2006-03-09T22:52:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![adamdorsey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ed8c4c/32.png) [@adamdorsey](https://www.ruby-forum.com/u/adamdorsey)\
**Post date:** [March 9, 2006, 10:52pm UTC](https://www.ruby-forum.com/t/turn-off-auto-increment/79248/1 "2006-03-09T22:52:44Z")

</div>

Hello,

I have an old table that handles sessions. the primary key is a field  
called session\_id and is the actual session id like “8df838303ufdfu838”

however when i do the following in the model:  
set\_primary\_key “session\_id”

and the following in the controller:

@session\_hash = { “session\_id” =\> @session.session\_id,  
“session\_user\_id” =\>  
@entry.user\_id, “session\_ip” =\> encode\_ip, “session\_time” =\> Time.now }

it wont update the session\_id as noted here in script/console:

> > sess = Session.new  
> > =\> #\<Session:0x407683f0 @attributes={“session\_start”=\>0,  
> > “session\_time”=\>0,  
> > “session\_ip”=\>“0”, “session\_admin”=\>0, “session\_page”=\>0,  
> > “session\_logged\_in”=\>false, “session\_user\_id”=\>0}, @new\_record=true\>
> 
> > sess.session\_id  
> > =\> nil
> 
> > sess.session\_id = ‘3893839393’  
> > NoMethodError: undefined method `session_id=' for #<Session:0x407683f0> from /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/base.rb:1498:in`method\_missing’  
> > from (irb):3

How do i enable manually setting the session\_id value ? If i comment out  
the  
“set\_primary\_key” line everything seems to break.

adam

---

<div class="post-metadata">

**Author:** ![adamdorsey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ed8c4c/32.png) [@adamdorsey](https://www.ruby-forum.com/u/adamdorsey)\
**Post date:** [March 9, 2006, 11:52pm UTC](https://www.ruby-forum.com/t/turn-off-auto-increment/79248/2 "2006-03-09T23:52:21Z")

</div>

Adam D. wrote:

> Hello,
> 
> I have an old table that handles sessions. the primary key is a field  
> called session\_id and is the actual session id like “8df838303ufdfu838”
> 
> however when i do the following in the model:  
> set\_primary\_key “session\_id”
> 
> and the following in the controller:
> 
> @session\_hash = { “session\_id” =\> @session.session\_id,  
> “session\_user\_id” =\>  
> @entry.user\_id, “session\_ip” =\> encode\_ip, “session\_time” =\> Time.now }
> 
> it wont update the session\_id as noted here in script/console:
> 
> > > sess = Session.new  
> > > =\> #\<Session:0x407683f0 @attributes={“session\_start”=\>0,  
> > > “session\_time”=\>0,  
> > > “session\_ip”=\>“0”, “session\_admin”=\>0, “session\_page”=\>0,  
> > > “session\_logged\_in”=\>false, “session\_user\_id”=\>0}, @new\_record=true\>  
> > > sess.session\_id  
> > > =\> nil  
> > > sess.session\_id = ‘3893839393’  
> > > NoMethodError: undefined method `session_id=' for #<Session:0x407683f0> from /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/base.rb:1498:in `method\_missing’  
> > > from (irb):3
> 
> How do i enable manually setting the session\_id value ? If i comment out  
> the  
> “set\_primary\_key” line everything seems to break.
> 
> adam

Even though you set\_primary\_key, you still use  
sess.id = ‘4543535345’

Joey  
[http://www.feedreed.com](http://www.feedreed.com)

---

<div class="post-metadata">

**Author:** ![adamdorsey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ed8c4c/32.png) [@adamdorsey](https://www.ruby-forum.com/u/adamdorsey)\
**Post date:** [March 10, 2006, 12:42am UTC](https://www.ruby-forum.com/t/turn-off-auto-increment/79248/3 "2006-03-10T00:42:38Z")

</div>

thanks. A note on this however… It seems you cant use a @params hash  
with  
“id” as one of the attributes and then do a sess= Session.new(@params).  
You have to do

sess = Session.new(@params)  
sess.id = somevalue

Not sure why but that is the only way i could get it to work.

adam
