How do I use a Rails ActiveRecord migration to insert a primary key into a MySQL database?
Posted
by Terry Lorber
on Stack Overflow
See other posts from Stack Overflow
or by Terry Lorber
Published on 2009-04-08T03:24:27Z
Indexed on
2010/06/10
22:52 UTC
Read the original article
Hit count: 350
I need to create an AR migration for a table of image files. The images are being checked into the source tree, and should act like attachment_fu files. That being the case, I'm creating a hierarchy for them under /public/system.
Because of the way attachment_fu generates links, I need to use the directory naming convention to insert primary key values. How do I override the auto-increment in MySQL as well as any Rails magic so that I can do something like this:
image = Image.create(:id => 42, :filename => "foo.jpg")
image.id #=> 42
© Stack Overflow or respective owner