Forum: Ruby on Rails Model.create ignores id attribute

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.
Bdf23c0219bd6c46856eba27ecf4c526?d=identicon&s=25 Anthony Lodi (lodi)
on 2006-04-19 15:59
Hello all,

I'm inserting records from another system and it looks something like
this:

Model.create :id=>123, :name=>"asdf"

I noticed that the id attribute is ignored (the database will
automatically assign an auto_increment id starting from 1).

I remember reading about this before: iirc this is done so that you can
easily fill in model information from forms, but I can't find any
documentation on this now.

Is there a way to force the id?  Or do I have to do:

m = Model.new( :name=>"asdf" )
m.id = 123
m.save

Thanks.
4daf0b71d5d9a3882e583c0e72eaf5dc?d=identicon&s=25 Alan Francis (Guest)
on 2006-04-19 16:15
Anthony Lodi wrote:
> Hello all,
>
> I'm inserting records from another system and it looks something like
> this:


I'd suggest you leave id as an auto-increment and create a new field
(oldsystem_id or something).

Alan
This topic is locked and can not be replied to.