Hi,
I tried to save User into database (postgresql) in manual transaction like this (there is only one save and is not necessary to use manual transaction, but it's only an example):
public function indexAction() {
$db = $this->di->get('db');
try {
$db->begin();
$gender = \Gender::findFirst(1);
// Create user object and set gender relation
$user = new User();
$user->setName('Rocky');
$user->gender = $gender;
// store user, but error occurs
$user->save();
$db->commit();
} catch (\Exception $e) {
$db->rollback();
}
/*
* The problem is here.
* Now, when the data are fetched via \Phalcon\MVC\Model, exception 'SQLSTATE[25P02]: In failed sql
* transaction: 7 ERROR: current transaction is aborted, commands ignored until end of transaction block' occurs
*
* If you can use raw sql below, it's correct
*/
$users = \User::find();
$db->commit();
// $sql = 'select * from users;';
// $result = $db->query($sql);
// $result->setFetchMode(\Phalcon\Db::FETCH_ASSOC);
// $result = $result->fetchAll($result);
}
When the save on the User failed, rollback is correct, but next find method fails, and PDO exception occurs:
SQLSTATE[25P02]: In failed sql transaction: 7 ERROR: current transaction is aborted, commands ignored until end of transaction block
DB connection is set shared in DI container.
When I try use raw sql (commented code in example) instead of model method find, data are fetched correctly.
In the db adapter is the transation level after rollback 1, after commit 0 (if all is ok).
I tried it with Phalcon version 1.3.4 and 2.0.7 and postgresql 9.3.
It's a bug? Thanks a lot.