j4mie / paris

A lightweight Active Record implementation for PHP5, built on top of Idiorm.
http://j4mie.github.com/idiormandparis/
996 stars 131 forks source link

pgsql driver returns oid instead of id after save() #42

Closed tassoevan closed 11 years ago

tassoevan commented 11 years ago
$obj->save();
echo $obj->id; // show the row oid

I know that exist an annoying problem in PDO pgsql driver that required the sequence name in lastInsertId() method. The sequence ID often has a column-based default name that can be used here, right?

tassoevan commented 11 years ago

Currently, I'm using the following workaround:

$obj->save();
$obj->id = $obj->orm->get_db()->lastInsertId('schema.table_id_seq');
treffynnon commented 11 years ago

Some code has just been added to the develop branch of Idiorm earlier today that uses PostgreSQL's RETURNING keyword to return last insert ID. Perhaps you could test that code out and let me know how you get on.

Just swap out idiorm.php in your project with the one in the develop branch of Idiorm after backing up.

I don't regularly use PostgreSQL so I cannot comment on your question in your initial issue report.

tassoevan commented 11 years ago

It works like a charm! I've forgot that RETURNING keyword is a better solution. Thanks for the answer and for this beautiful ORM library!