ActiveRecord, insert and not auto-incremented primary keys...


After playing while with ActiveRecord, I'm surprised it isn't easier to insert data into a table whose primary key is not auto-incremented by the database server.

The following code...

Philippe Lang wrote:

class Garden < ActiveRecord::Base   set_primary_key :code end

garden ="code" => 1, "name" => "garden1")

When you use set_primary_key, ActiveRecord maps your key to the attribute "id" behind the scenes. So you still use "id".

- Mark.