Here's an abbreviated test case:

$id = String::uuid();
$data = array(
    'Model1' => array(
        'a_field' => 'something'
    ),
    'Model2' => array(array(
        'another_field' => 'another_something'
    )),
    'Model3' => array(
        'id' => $id,
        'some_field' => 'some_value',
        'special_id' => $special_id
    ),
    'Model4' => array(array(
        'id' => String::uuid(),
        'special_id' => $special_id,
        'model3_id' => $id5
    ))
);
$this->assertFalse($this->Model1->findByName($data['Model1']
['name']));     //as expected, this record does not exist
$this->Model1->create();
$save1 = array('Model1' => $data['Model1'], 'Model2' => $data
['Model2']);
$this->Model1->query('SET AUTOCOMMIT = 0');
$this->Model1->query('START TRANSACTION');
if($this->Model1->saveAll($save1, array('validate' => 'first',
'atomic' => false))) {
    $newModel1Data = $this->Model1->findByName($data['Model1']
['name']);
    $save2 = array(
        'Model3' => $data['Model3'],
        'Model1' => array('Model1' => array($newModel1Data['Model1']
['id'])),
        'Model4' => $data['Model4']
    );
    if($this->Model3->saveAll($save2, array('validate' => 'first',
'atomic' => false))) {
        $this->Model1->query('COMMIT');
    } else {
        $this->Model1->query('ROLLBACK');
    }
} else {
    $this->Model1->query('ROLLBACK');
}
$this->assertFalse($this->Model3->read(null, $id));  //as expected,
model3 record was not created
$this->assertFalse($this->Model1->findByName($data['Model1']
['name']));  //unexpected, model1 record was created
$this->assertFalse($this->Model2->find('count', array(   //as
expected, model2 record was not created
    'conditions' => array(
        'Model2.another_field' => 'another_something'
    ),
    'recursive' => -1
)));

For what it's worth, I've tried replacing $this->Model1->query('START
TRANSACTION'); with $model1datasource = $this->Model1->getDataSource
(); $model1datasource->begin($this->Model1); and $this->Model1->query
('COMMIT'); with $model1datasource->commit($this->Model1); and $this-
>Model1->query('ROLLBACK'); with $model1datasource->rollback($this-
>Model1); with no change in result.  $model1datasource-
>_transactionStarted correctly returns the expected result at each
stage.

--

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=.


Reply via email to