writeCreate/postCreate issue
writeCreate/postCreate issue
Hi,
For some reason
$editor->on('writeCreate',function( $editor, $id, $values ) use ($pdo) {
print_r($pdo->query('SELECT * FROM `table` WHERE id=:id',array('id'=>$id))->results());
});
or
$editor->on('postCreate',function( $editor, $id, $values, $row ) use ($pdo) {
print_r($pdo->query('SELECT * FROM `table` WHERE id=:id',array('id'=>$id))->results());
});
prints me an empty array.
I would expect to get the data instead. $id, $values, $row already exist, but the data is not yet physically written into the DB. I need to run a query with a simple JOIN, which is impossible to execute because the row is still not there. What should I do?
Thanks,
This discussion has been closed.
Replies
Hi Tom,
Is
$pdo
a separate PDO instance from theDatabase
instance that the Editor constructor is given (i.e. are you using two PDO instances, or one). I'm guessing two! Editor uses a transaction by default, so if you use a second instance, it will be reading outside the transaction and thus will get the stale data.Try:
That will use the PDO instance that Editor is using. Database API docs available here.
Allan
Hello Allan,
That's what I needed. Thank you. It works.