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

Howard Yeh
Thu, 17 Sep 2009 20:42:55 -0000

On Sep 16, 6:48 pm, Marnen Laibow-Koser <rails-mailing-l...@andreas-
s.net> wrote:
> 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.

The particular case is for a has_many association, but I want to avoid
the overhead of having two indices.

It''ll be insertion only, so duplicate foreign key is acceptable.

The association has the bag semantics.

If this doesn''t work, what''s "create_table :id =>
false"  ever used
for?

> [...]
>
>
>
> > 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-Koserhttp://www.marnen.org
> mar...-sbuyVjPbboAdnm+yROfE0A@public.gmane.org
> --
> Posted viahttp://www.ruby-forum.com/.