Reputation: 315
How would one add a RETURNING clause in insert via table gateway ?
INSERT INTO users (name, age) VALUES ('Liszt', 10) RETURNING id;
Upvotes: 1
Views: 223
Reputation: 1222
if you want to get last insert id in postgresql when inserting into tablegateway you have to use SequenceFeature.
$myTable = new TableGateway('table_name', $dbAdapter, new Feature\SequenceFeature('primary_key', 'sequence_name'));
$id = $myTable->insert(array(/*your data*/));
Upvotes: 0
Reputation: 4635
$dataArray = array('name'=> 'Liszt','age' => 10);
$this->tableGateway->insert($dataArray);
$userId = $this->tableGateway->lastInsertValue;
Another method is :
$userId = $this->tableGateway->getLastInsertValue();
Upvotes: 2