Forum: Ruby on Rails turn off auto increment

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
F15fdc7cb2e911b3808837f2be244add?d=identicon&s=25 Adam Denenberg (Guest)
on 2006-03-09 22:52
(Received via mailing list)
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
6dab365a82517fb694650a57ee88e4a4?d=identicon&s=25 joey__ (Guest)
on 2006-03-09 23:52
Adam Denenberg 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
F15fdc7cb2e911b3808837f2be244add?d=identicon&s=25 Adam Denenberg (Guest)
on 2006-03-10 00:42
(Received via mailing list)
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
This topic is locked and can not be replied to.