Magento でトランザクションを使用しています。最初の挿入クエリのprimaryKeyを後続のすべてのクエリに使用する必要があります。
$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
トランザクションを保存する前に最後に挿入された ID を取得する方法