【发布时间】:2015-06-12 10:36:55
【问题描述】:
在 cakephp3 中进行事务并在其中添加 get() 查询时一切正常。但是为什么在事务内部没有执行 find() 查询呢?
我在 cakephp3 中有以下控制器:
<?php
namespace App\Controller;
use Cake\Core\Configure;
use Cake\Network\Exception\NotFoundException;
use Cake\View\Exception\MissingTemplateException;
use Cake\Network\Session;
use Cake\Event\Event;
use Cake\Network\Http\Client;
use Cake\ORM\TableRegistry;
use Cake\Datasource\ConnectionManager;
class DashboardController extends AppController {
public function index(){
$conn = ConnectionManager::get('default');
$testModel = TableRegistry::get('Tests');
$select1=array();
$select2 = array();
$saved = array();
$conn->transactional(function ($connection)use(&$testModel,&$select1,&$select2,&$saved) {
$select1 = $testModel->find('all')->where(['id' => 2]); // article with id 12
$select2 = $testModel->get(1);
$select2->content = 'foo';
$saved = $testModel->save($select2);
});
}
}
?>
我希望在 SQL 日志中得到这个:
BEGIN
SELECT Tests.id AS `Tests__id`, Tests.content AS `Tests__content` FROM tests Tests WHERE id = 2
SELECT Tests.id AS `Tests__id`, Tests.content AS `Tests__content` FROM tests Tests WHERE Tests.id = 1 LIMIT 1
UPDATE tests SET content = 'foo' WHERE id = 1
COMMIT
但是我得到了:
BEGIN
SELECT Tests.id AS `Tests__id`, Tests.content AS `Tests__content` FROM tests Tests WHERE Tests.id = 1 LIMIT 1
UPDATE tests SET content = 'foo' WHERE id = 1
COMMIT
SELECT Tests.id AS `Tests__id`, Tests.content AS `Tests__content` FROM tests Tests WHERE id = 2
【问题讨论】:
标签: mysql select transactions cakephp-3.0