Cakephp Classroom image

Anil  Bist / Professional / Web Technology

 
To post your Question Join Classroom
 
Lesson Topics's No:-  First|78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86|Last
Lessons:-Models

A common workaround for this implementation issue is to copy virtualFields from one model to
another at runtime when you need to access them:
$this->virtualFields[’name’] = $this->Author->virtualFields[’name’];
or:
$this->virtualFields += $this->Author->virtualFields;
Transactions
To perform a transaction, a model’s tables must be of a type that supports transactions.
All transaction methods must be performed on a model’s DataSource object. To get a model’s DataSource
from within the model, use:
$dataSource = $this->getDataSource();
You can then use the data source to start, commit, or roll back transactions.
$dataSource->begin();
// Perform some tasks
if (/*all’s well*/) {
$dataSource->commit();
} else {
$dataSource->rollback();
}
Nested Transactions
It is possible to start a transaction several times using the Datasource::begin() method. The transaction
will finish only when the number of commit and rollback match with begin’s.
$dataSource->begin();
// Perform some tasks
$dataSource->begin();
// More few tasks
if (/*latest task ok*/) {
$dataSource->commit();
} else {
$dataSource->rollback();
// Change something in main task
}
$dataSource->commit();
This will perform the real nested transaction if your database supports it and it is enabled in the datasource.
The methods will always return true when in transaction mode and the nested is not supported or disabled.
If you want to use multiple begin’s but not use the nested transaction from database, disable it using
$dataSource->useNestedTransactions = false;. It will use only the global transaction.

 
 
 
image
Anil  Bist

Skills    Cakephp

Qualifications :- High School - SLV, College/University - Graphic Era Deemed Univ University,
Location :-Dehradun,Dehradun,Uttarakhand,India
Description:-

I started my Professional Journey in 2006 with one of the Web Development Company in Bangalore and my 1st framework was "Ruby on Rail" as Web development and delivered around 5+ Projects using this platform. Then came another dimension as JEE/Sturst framework, Gradually I realized that I want to build something on my own and give my passion and energy on creating something different a
Explore

 

  Students (0)