Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Rails does not detect primary key value with postgres when not using sequences

#6161

Rails does not detect the primary key value of new saved objects when the primary key is not a sequence, and the value is generated by another default function.

                         Table "public.moo"
 Column |         Type          |              Modifiers
--------+-----------------------+-------------------------------------
 id     | uuid                  | not null default uuid_generate_v4()
 moo    | character varying(64) |
Indexes:
    "moo_pkey" PRIMARY KEY, btree (id)

This works perfectly when using the postgresql command line;

INSERT INTO moo(moo) VALUES('moo') RETURNING id;
                  id
--------------------------------------
 9a5374a9-0bf3-4196-b68b-e1dd6ab69f69
(1 row)
INSERT INTO moo(moo) VALUES('moo') RETURNING id;
                  id
--------------------------------------
 a107f5da-f013-4c15-83e8-fb0220fa3918
(1 row)

etc..

When using the framework the id isn't retrieved:

irb(main):006:0> blah = Moo.create(:moo => 'testing123')
=> #<Moo id: nil, moo: "testing123">
irb(main):007:0> Moo.find_by_moo('testing123')
=> #<Moo id: "c4c3ea70-61d9-4d4b-baae-aa6adde0b58b", moo: "testing123">

Tested with Rails 3.0.3 and PostgreSQL 8.3.12.

Reported by Kjetil Lerøen · December 13th, 2010 @ 09:00 PM

State: resolved
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. Kjetil Lerøen
    Kjetil Lerøen

    Seems to work now in edge rails. Thanks Aaron.

    December 14th, 2010 @ 01:25 AM

  2. Piotr Sarnacki
    Piotr Sarnacki
    • State changed from new to resolved
    • Importance changed from to Low

    I'm closing that ticket as resolved, if someone needs it backported to 3-0-stable badly, please comment.

    December 14th, 2010 @ 09:55 AM