I am using transactions in Magento. I need to use primeryKey of first insert query to all my subsequent queries.
$model1->setfield1()
->setField2();
$transaction->addObject($model1);
$connection = Mage::getSingleton('core/resource')->getConnection('core_read');
$lastInsertId = $connection->fetchOne('SELECT last_insert_id()'); // return 0
$model2->setfield3($lastInsertId )
$model3->setfield4($lastInsertId )
$transaction->addObject($model2);
$transaction->addObject($model3);
$transaction-Save();
$lastInsertId2 = $connection->fetchOne('SELECT last_insert_id()'); // returns correct result
how to get last inserted id before saving the transaction