cphalcon: [BUG] New record, PostgreSQL and the Primary key
Test table in postgres:
CREATE TABLE robots
(
id serial NOT NULL,
name character varying,
CONSTRAINT robots_pkey PRIMARY KEY (id)
);
Model:
class Robot extends \Phalcon\Mvc\Model
{
public function getSource()
{
return 'robots';
}
}
Scenario №1:
$robot = new Robot();
$robot->name = uniqid();
$robot->save();
result: OK
Scenario №2
$robot = new Robot();
$robot->id = 666; // predefined primary key
$robot->name = uniqid();
$robot->save();
result: “PDOException: SQLSTATE[55000]: Object not in prerequisite state: 7 ERROR: currval of sequence “robots_id_seq” is not yet defined in this session”
Scenario №3
$robot = new Robot();
$robot->id = $robot->getReadConnection()->fetchOne("SELECT NEXTVAL('robots_id_seq') as id")['id']; // predefined primary key from sequence
$robot->name = uniqid();
$robot->save(); //OK
//but:
$robot->refresh();
result: “Phalcon\Mvc\Model\Exception: The record cannot be refreshed because it does not exist or is deleted”
<bountysource-plugin>
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource. </bountysource-plugin>
About this issue
- Original URL
- State: closed
- Created 11 years ago
- Reactions: 1
- Comments: 17 (9 by maintainers)
MUCH better workaround: put this in your model.
Bam!