Re: postgres adapater problem with create_table :id => false

Marnen Laibow-Koser
Thu, 17 Sep 2009 01:48:22 -0000

Howard Yeh wrote:
> Hi All,
>
> When saving a record to a table that doesn''t use primary key, the
> adapater raises
>
> ActiveRecord::StatementInvalid: PGError: ERROR:  column "id" does
not
> exist
>
[....]
>
> The problem is that ActiveRecord::Base.create
> would pass in the primary_key "id" for the
> parameter pk even though the ActiveRecord class
> doesn''t have a primary key.

When would you ever want to use an AR model without a primary key?  The
only case I can think of where Rails doesn''t want a primary key is on
habtm join tables, which don''t have an associated model class.

[...]
>
>
> Or is there a way to set the primary key to nil?
>
> class Foo < ActiveRecord::Base
>  set_primary_key nil
>  primary_key # => ""
> end

Seems like a really bad idea.  Without a primary key, there is no way to
uniquely identify a record.  Why do you want to do this?

>
> Howard

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org
--
Posted via http://www.ruby-forum.com/.