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
[aegis:/tmp/test] ryan% rake db:migrate
[aegis:/tmp/test] ryan% ./script/console
Loading development environment.
blah = Blah.create
blah.id = 500
ActiveRecord::RecordNotFound: Couldn’t find Blah with ID=500
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.