I’m using Postgre 9 and I am connecting to it via PDO. I used schema from auth-schema-postgresql.sql, so tables should be fine.
I’m doing something like that:
$post = $this->request->post();
$member = new Model_User(); // ORM::factory('user');s
$member->create_user($post, array('email', 'username', 'password'));
Model user is nothing fancy
<?php defined('SYSPATH') or die('No direct access allowed.');
class Model_User extends Model_Auth_User {
protected $_table_columns = array(
'id' => NULL,
'email' => NULL,
'username' => NULL,
'password' => NULL,
'logins' => NULL,
'last_login' => NULL
);
} // End User Model
The problem is the id value in $member->object() equals false after save (same for pk() and $member->id). Row is being created fine, it has it’s id, but I’d very like to have that number given by the pk() method.
In PDO you must supply the name of the Sequence object associated to the primary key of the table User. It would probably be user_id_sequence.
Navigate to the file “modules/database/classes/Kohana/Database/PDO.php”. In the following lines of code (188-196):
The name of the sequence object must be passed as an argument of the $this->_connection->lastInsertId() method as in the following:
This way, the ORM model can “be aware” of the new record’s id auto-incremented by the sequence and therefore the pk() method will work fine.