Forum: Ruby on Rails Can't set id on objects?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Ryan (Guest)
on 2007-03-02 03:07
(Received via mailing list)
I'm revamping an app I wrote a couple months ago and have just
discovered that I cannot set the id of new or existing objects.

[aegis:~] ryan% cd /tmp/
[aegis:/tmp] ryan% rails test
[aegis:/tmp] ryan% cd test
[aegis:/tmp/test] ryan% ./script/generate scaffold_resource blah
id:integer title:string
[aegis:/tmp/test] ryan% rake db:migrate
[aegis:/tmp/test] ryan% ./script/console
Loading development environment.
>> blah = Blah.create
>> = 500
=> 500
=> true
>> blah.reload
ActiveRecord::RecordNotFound: Couldn't find Blah with ID=500
>> Blah.find(:first).id
=> 1

When did id become protected and unmodifiable? I know for certain that
I *used* to be able to set the id of objects, as I have a table full
of examples where this was successfully done. I'm also fairly certain
I didn't have to jump through any hoops to get that behavior...

Is it simply impossible to set the id of an object now? I can sort of
see why this is a desirable default, but is there some way to override
that behavior in my models? If not, that's unfortunate, as I now have
to go mucking with a bunch of other code that I had hoped to leave be.

This topic is locked and can not be replied to.