This project is archived and is in readonly mode.
Rails does not detect primary key value with postgres when not using sequences
Reported by Kjetil Lerøen | December 13th, 2010 @ 09:00 PM
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.
Comments and changes to this ticket
-
Piotr Sarnacki December 14th, 2010 @ 09:55 AM
- 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.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>