# Can't set id on objects?

**URL:** <https://www.ruby-forum.com/t/cant-set-id-on-objects/87373>\
**Category:** Rails\
**Created:** [March 2, 2007, 2:07am UTC](https://www.ruby-forum.com/t/cant-set-id-on-objects/87373 "2007-03-02T02:07:16Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ryan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/a8b319/32.png) [@ryan](https://www.ruby-forum.com/u/ryan)\
**Post date:** [March 2, 2007, 2:07am UTC](https://www.ruby-forum.com/t/cant-set-id-on-objects/87373/1 "2007-03-02T02:07:16Z")

</div>

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  
> > blah.id = 500  
> > =\> 500
> 
> > blah.save  
> > =\> 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.

–  
Ryan
