RE: [Rails] Re: ActiveRecord, insert and not auto-incremented primary keys...

Philippe Lang wrote:

class Garden < ActiveRecord::Base
  set_primary_key :code
end

garden = Garden.new("code" => 1, "name" => "garden1") garden.save

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

- Mark.

Let's see the problem differently:

The primary key attribute is protected from mass assignment, so can't
be set by passing its value in a hash. Try this instead:

i = Inc.new("name" => "to inc or not to inc?")
i.id = 123
i.save

Tom