ActiveRecord.php 18.7 KB
Newer Older
w  
Qiang Xue committed
1 2 3 4
<?php
/**
 * @author Qiang Xue <qiang.xue@gmail.com>
 * @link http://www.yiiframework.com/
Qiang Xue committed
5
 * @copyright Copyright (c) 2008 Yii Software LLC
w  
Qiang Xue committed
6 7 8
 * @license http://www.yiiframework.com/license/
 */

Qiang Xue committed
9
namespace yii\db;
w  
Qiang Xue committed
10

Qiang Xue committed
11
use yii\base\InvalidConfigException;
12
use yii\helpers\Inflector;
13
use yii\helpers\StringHelper;
w  
Qiang Xue committed
14

w  
Qiang Xue committed
15
/**
Qiang Xue committed
16
 * ActiveRecord is the base class for classes representing relational data in terms of objects.
w  
Qiang Xue committed
17
 *
Qiang Xue committed
18
 * @include @yii/db/ActiveRecord.md
w  
Qiang Xue committed
19
 *
Qiang Xue committed
20
 * @author Qiang Xue <qiang.xue@gmail.com>
21
 * @author Carsten Brandt <mail@cebe.cc>
Qiang Xue committed
22
 * @since 2.0
w  
Qiang Xue committed
23
 */
24
class ActiveRecord extends BaseActiveRecord
w  
Qiang Xue committed
25
{
26
	/**
27
	 * The insert operation. This is mainly used when overriding [[transactions()]] to specify which operations are transactional.
28
	 */
29
	const OP_INSERT = 0x01;
30
	/**
31
	 * The update operation. This is mainly used when overriding [[transactions()]] to specify which operations are transactional.
32
	 */
33
	const OP_UPDATE = 0x02;
34
	/**
35
	 * The delete operation. This is mainly used when overriding [[transactions()]] to specify which operations are transactional.
36
	 */
37 38 39 40 41 42
	const OP_DELETE = 0x04;
	/**
	 * All three operations: insert, update, delete.
	 * This is a shortcut of the expression: OP_INSERT | OP_UPDATE | OP_DELETE.
	 */
	const OP_ALL = 0x07;
43

Qiang Xue committed
44 45 46 47 48 49
	/**
	 * Returns the database connection used by this AR class.
	 * By default, the "db" application component is used as the database connection.
	 * You may override this method if you want to use a different database connection.
	 * @return Connection the database connection used by this AR class.
	 */
Qiang Xue committed
50
	public static function getDb()
Qiang Xue committed
51
	{
Qiang Xue committed
52
		return \Yii::$app->getDb();
Qiang Xue committed
53 54
	}

Qiang Xue committed
55
	/**
Qiang Xue committed
56 57 58 59 60 61 62 63 64 65 66 67 68
	 * Creates an [[ActiveQuery]] instance with a given SQL statement.
	 *
	 * Note that because the SQL statement is already specified, calling additional
	 * query modification methods (such as `where()`, `order()`) on the created [[ActiveQuery]]
	 * instance will have no effect. However, calling `with()`, `asArray()` or `indexBy()` is
	 * still fine.
	 *
	 * Below is an example:
	 *
	 * ~~~
	 * $customers = Customer::findBySql('SELECT * FROM tbl_customer')->all();
	 * ~~~
	 *
Qiang Xue committed
69 70
	 * @param string $sql the SQL statement to be executed
	 * @param array $params parameters to be bound to the SQL statement during execution.
Qiang Xue committed
71
	 * @return ActiveQuery the newly created [[ActiveQuery]] instance
Qiang Xue committed
72
	 */
Alexander Makarov committed
73
	public static function findBySql($sql, $params = [])
w  
Qiang Xue committed
74
	{
Qiang Xue committed
75
		$query = static::createQuery();
Qiang Xue committed
76 77 78 79 80 81
		$query->sql = $sql;
		return $query->params($params);
	}

	/**
	 * Updates the whole table using the provided attribute values and conditions.
Qiang Xue committed
82 83 84
	 * For example, to change the status to be 1 for all customers whose status is 2:
	 *
	 * ~~~
Alexander Makarov committed
85
	 * Customer::updateAll(['status' => 1], 'status = 2');
Qiang Xue committed
86 87 88 89
	 * ~~~
	 *
	 * @param array $attributes attribute values (name-value pairs) to be saved into the table
	 * @param string|array $condition the conditions that will be put in the WHERE part of the UPDATE SQL.
Qiang Xue committed
90
	 * Please refer to [[Query::where()]] on how to specify this parameter.
resurtm committed
91
	 * @param array $params the parameters (name => value) to be bound to the query.
Qiang Xue committed
92 93
	 * @return integer the number of rows updated
	 */
Alexander Makarov committed
94
	public static function updateAll($attributes, $condition = '', $params = [])
w  
Qiang Xue committed
95
	{
Qiang Xue committed
96
		$command = static::getDb()->createCommand();
Qiang Xue committed
97 98
		$command->update(static::tableName(), $attributes, $condition, $params);
		return $command->execute();
w  
Qiang Xue committed
99 100
	}

Qiang Xue committed
101
	/**
Qiang Xue committed
102 103 104 105
	 * Updates the whole table using the provided counter changes and conditions.
	 * For example, to increment all customers' age by 1,
	 *
	 * ~~~
Alexander Makarov committed
106
	 * Customer::updateAllCounters(['age' => 1]);
Qiang Xue committed
107 108
	 * ~~~
	 *
Qiang Xue committed
109
	 * @param array $counters the counters to be updated (attribute name => increment value).
Qiang Xue committed
110 111
	 * Use negative values if you want to decrement the counters.
	 * @param string|array $condition the conditions that will be put in the WHERE part of the UPDATE SQL.
Qiang Xue committed
112
	 * Please refer to [[Query::where()]] on how to specify this parameter.
resurtm committed
113
	 * @param array $params the parameters (name => value) to be bound to the query.
Qiang Xue committed
114
	 * Do not name the parameters as `:bp0`, `:bp1`, etc., because they are used internally by this method.
Qiang Xue committed
115 116
	 * @return integer the number of rows updated
	 */
Alexander Makarov committed
117
	public static function updateAllCounters($counters, $condition = '', $params = [])
w  
Qiang Xue committed
118
	{
Qiang Xue committed
119
		$n = 0;
Qiang Xue committed
120
		foreach ($counters as $name => $value) {
Alexander Makarov committed
121
			$counters[$name] = new Expression("[[$name]]+:bp{$n}", [":bp{$n}" => $value]);
Qiang Xue committed
122
			$n++;
Qiang Xue committed
123
		}
124
		$command = static::getDb()->createCommand();
Qiang Xue committed
125 126
		$command->update(static::tableName(), $counters, $condition, $params);
		return $command->execute();
w  
Qiang Xue committed
127 128
	}

Qiang Xue committed
129 130
	/**
	 * Deletes rows in the table using the provided conditions.
Qiang Xue committed
131 132 133 134 135 136 137 138 139
	 * WARNING: If you do not specify any condition, this method will delete ALL rows in the table.
	 *
	 * For example, to delete all customers whose status is 3:
	 *
	 * ~~~
	 * Customer::deleteAll('status = 3');
	 * ~~~
	 *
	 * @param string|array $condition the conditions that will be put in the WHERE part of the DELETE SQL.
Qiang Xue committed
140
	 * Please refer to [[Query::where()]] on how to specify this parameter.
resurtm committed
141
	 * @param array $params the parameters (name => value) to be bound to the query.
Qiang Xue committed
142
	 * @return integer the number of rows deleted
Qiang Xue committed
143
	 */
Alexander Makarov committed
144
	public static function deleteAll($condition = '', $params = [])
w  
Qiang Xue committed
145
	{
Qiang Xue committed
146
		$command = static::getDb()->createCommand();
Qiang Xue committed
147 148
		$command->delete(static::tableName(), $condition, $params);
		return $command->execute();
w  
Qiang Xue committed
149 150
	}

.  
Qiang Xue committed
151
	/**
Qiang Xue committed
152
	 * Creates an [[ActiveQuery]] instance.
153
	 *
154
	 * This method is called by [[find()]], [[findBySql()]] to start a SELECT query.
Qiang Xue committed
155 156
	 * You may override this method to return a customized query (e.g. `CustomerQuery` specified
	 * written for querying `Customer` purpose.)
157 158 159 160 161 162 163 164 165 166 167 168 169
	 *
	 * You may also define default conditions that should apply to all queries unless overridden:
	 *
	 * ```php
	 * public static function createQuery()
	 * {
	 *     return parent::createQuery()->where(['deleted' => false]);
	 * }
	 * ```
	 *
	 * Note that all queries should use [[Query::andWhere()]] and [[Query::orWhere()]] to keep the
	 * default condition. Using [[Query::where()]] will override the default condition.
	 *
Qiang Xue committed
170
	 * @return ActiveQuery the newly created [[ActiveQuery]] instance.
.  
Qiang Xue committed
171
	 */
Qiang Xue committed
172
	public static function createQuery()
w  
Qiang Xue committed
173
	{
Alexander Makarov committed
174
		return new ActiveQuery(['modelClass' => get_called_class()]);
w  
Qiang Xue committed
175 176 177
	}

	/**
Qiang Xue committed
178
	 * Declares the name of the database table associated with this AR class.
179
	 * By default this method returns the class name as the table name by calling [[Inflector::camel2id()]]
180 181 182
	 * with prefix [[DbConnection::tablePrefix]]. For example if [[DbConnection::tablePrefix]] is 'tbl_',
	 * 'Customer' becomes 'tbl_customer', and 'OrderItem' becomes 'tbl_order_item'. You may override this method
	 * if the table is not named after this convention.
w  
Qiang Xue committed
183 184
	 * @return string the table name
	 */
Qiang Xue committed
185
	public static function tableName()
w  
Qiang Xue committed
186
	{
187
		return '{{%' . Inflector::camel2id(StringHelper::basename(get_called_class()), '_') . '}}';
w  
Qiang Xue committed
188 189 190
	}

	/**
Qiang Xue committed
191 192
	 * Returns the schema information of the DB table associated with this AR class.
	 * @return TableSchema the schema information of the DB table associated with this AR class.
193
	 * @throws InvalidConfigException if the table for the AR class does not exist.
w  
Qiang Xue committed
194
	 */
Qiang Xue committed
195
	public static function getTableSchema()
w  
Qiang Xue committed
196
	{
197 198 199 200 201 202
		$schema = static::getDb()->getTableSchema(static::tableName());
		if ($schema !== null) {
			return $schema;
		} else {
			throw new InvalidConfigException("The table does not exist: " . static::tableName());
		}
w  
Qiang Xue committed
203 204 205
	}

	/**
Qiang Xue committed
206 207
	 * Returns the primary key name(s) for this AR class.
	 * The default implementation will return the primary key(s) as declared
Qiang Xue committed
208
	 * in the DB table that is associated with this AR class.
Qiang Xue committed
209
	 *
Qiang Xue committed
210 211 212
	 * If the DB table does not declare any primary key, you should override
	 * this method to return the attributes that you want to use as primary keys
	 * for this AR class.
Qiang Xue committed
213 214 215
	 *
	 * Note that an array should be returned even for a table with single primary key.
	 *
Qiang Xue committed
216
	 * @return string[] the primary keys of the associated database table.
w  
Qiang Xue committed
217
	 */
Qiang Xue committed
218
	public static function primaryKey()
w  
Qiang Xue committed
219
	{
Qiang Xue committed
220
		return static::getTableSchema()->primaryKey;
w  
Qiang Xue committed
221 222
	}

223
	/**
224 225 226
	 * Returns the list of all attribute names of the model.
	 * The default implementation will return all column names of the table associated with this AR class.
	 * @return array list of attribute names.
227
	 */
228
	public function attributes()
229
	{
230
		return array_keys(static::getTableSchema()->columns);
231 232
	}

233 234 235 236 237 238 239 240 241 242 243
	/**
	 * Declares which DB operations should be performed within a transaction in different scenarios.
	 * The supported DB operations are: [[OP_INSERT]], [[OP_UPDATE]] and [[OP_DELETE]],
	 * which correspond to the [[insert()]], [[update()]] and [[delete()]] methods, respectively.
	 * By default, these methods are NOT enclosed in a DB transaction.
	 *
	 * In some scenarios, to ensure data consistency, you may want to enclose some or all of them
	 * in transactions. You can do so by overriding this method and returning the operations
	 * that need to be transactional. For example,
	 *
	 * ~~~
Alexander Makarov committed
244
	 * return [
245 246 247 248 249
	 *     'admin' => self::OP_INSERT,
	 *     'api' => self::OP_INSERT | self::OP_UPDATE | self::OP_DELETE,
	 *     // the above is equivalent to the following:
	 *     // 'api' => self::OP_ALL,
	 *
Alexander Makarov committed
250
	 * ];
251 252 253 254 255 256 257 258 259 260 261
	 * ~~~
	 *
	 * The above declaration specifies that in the "admin" scenario, the insert operation ([[insert()]])
	 * should be done in a transaction; and in the "api" scenario, all the operations should be done
	 * in a transaction.
	 *
	 * @return array the declarations of transactional operations. The array keys are scenarios names,
	 * and the array values are the corresponding transaction operations.
	 */
	public function transactions()
	{
Alexander Makarov committed
262
		return [];
263 264
	}

265 266 267 268 269 270 271
	/**
	 * Creates an [[ActiveRelation]] instance.
	 * This method is called by [[hasOne()]] and [[hasMany()]] to create a relation instance.
	 * You may override this method to return a customized relation.
	 * @param array $config the configuration passed to the ActiveRelation class.
	 * @return ActiveRelation the newly created [[ActiveRelation]] instance.
	 */
272
	public static function createActiveRelation($config = [])
273 274
	{
		return new ActiveRelation($config);
Qiang Xue committed
275 276
	}

Qiang Xue committed
277
	/**
Qiang Xue committed
278 279 280 281 282 283
	 * Inserts a row into the associated database table using the attribute values of this record.
	 *
	 * This method performs the following steps in order:
	 *
	 * 1. call [[beforeValidate()]] when `$runValidation` is true. If validation
	 *    fails, it will skip the rest of the steps;
284 285
	 * 2. call [[afterValidate()]] when `$runValidation` is true.
	 * 3. call [[beforeSave()]]. If the method returns false, it will skip the
Qiang Xue committed
286
	 *    rest of the steps;
287 288
	 * 4. insert the record into database. If this fails, it will skip the rest of the steps;
	 * 5. call [[afterSave()]];
Qiang Xue committed
289
	 *
290
	 * In the above step 1, 2, 3 and 5, events [[EVENT_BEFORE_VALIDATE]],
Qiang Xue committed
291 292
	 * [[EVENT_BEFORE_INSERT]], [[EVENT_AFTER_INSERT]] and [[EVENT_AFTER_VALIDATE]]
	 * will be raised by the corresponding methods.
Qiang Xue committed
293
	 *
294
	 * Only the [[dirtyAttributes|changed attribute values]] will be inserted into database.
Qiang Xue committed
295 296
	 *
	 * If the table's primary key is auto-incremental and is null during insertion,
Qiang Xue committed
297
	 * it will be populated with the actual value after insertion.
Qiang Xue committed
298 299 300 301 302 303 304 305 306 307 308 309
	 *
	 * For example, to insert a customer record:
	 *
	 * ~~~
	 * $customer = new Customer;
	 * $customer->name = $name;
	 * $customer->email = $email;
	 * $customer->insert();
	 * ~~~
	 *
	 * @param boolean $runValidation whether to perform validation before saving the record.
	 * If the validation fails, the record will not be inserted into the database.
Qiang Xue committed
310 311 312
	 * @param array $attributes list of attributes that need to be saved. Defaults to null,
	 * meaning all attributes that are loaded from DB will be saved.
	 * @return boolean whether the attributes are valid and the record is inserted successfully.
313
	 * @throws \Exception in case insert failed.
Qiang Xue committed
314
	 */
Qiang Xue committed
315
	public function insert($runValidation = true, $attributes = null)
Qiang Xue committed
316
	{
317 318 319 320
		if ($runValidation && !$this->validate($attributes)) {
			return false;
		}
		$db = static::getDb();
Qiang Xue committed
321 322 323 324
		if ($this->isTransactional(self::OP_INSERT) && $db->getTransaction() === null) {
			$transaction = $db->beginTransaction();
			try {
				$result = $this->insertInternal($attributes);
resurtm committed
325
				if ($result === false) {
326 327 328 329
					$transaction->rollback();
				} else {
					$transaction->commit();
				}
Qiang Xue committed
330
			} catch (\Exception $e) {
331
				$transaction->rollback();
Qiang Xue committed
332
				throw $e;
333
			}
Qiang Xue committed
334 335
		} else {
			$result = $this->insertInternal($attributes);
336 337 338 339 340 341 342
		}
		return $result;
	}

	/**
	 * @see ActiveRecord::insert()
	 */
resurtm committed
343
	private function insertInternal($attributes = null)
344 345
	{
		if (!$this->beforeSave(true)) {
Qiang Xue committed
346 347
			return false;
		}
348 349
		$values = $this->getDirtyAttributes($attributes);
		if (empty($values)) {
350 351
			foreach ($this->getPrimaryKey(true) as $key => $value) {
				$values[$key] = $value;
Qiang Xue committed
352
			}
353 354 355
		}
		$db = static::getDb();
		$command = $db->createCommand()->insert($this->tableName(), $values);
356 357 358 359 360 361
		if (!$command->execute()) {
			return false;
		}
		$table = $this->getTableSchema();
		if ($table->sequenceName !== null) {
			foreach ($table->primaryKey as $name) {
362 363 364 365
				if ($this->getAttribute($name) === null) {
					$id = $db->getLastInsertID($table->sequenceName);
					$this->setAttribute($name, $id);
					$this->setOldAttribute($name, $id);
366
					break;
Qiang Xue committed
367 368 369
				}
			}
		}
370
		foreach ($values as $name => $value) {
371
			$this->setOldAttribute($name, $value);
372 373 374
		}
		$this->afterSave(true);
		return true;
Qiang Xue committed
375 376 377
	}

	/**
Qiang Xue committed
378 379 380 381 382 383
	 * Saves the changes to this active record into the associated database table.
	 *
	 * This method performs the following steps in order:
	 *
	 * 1. call [[beforeValidate()]] when `$runValidation` is true. If validation
	 *    fails, it will skip the rest of the steps;
384 385
	 * 2. call [[afterValidate()]] when `$runValidation` is true.
	 * 3. call [[beforeSave()]]. If the method returns false, it will skip the
Qiang Xue committed
386
	 *    rest of the steps;
387 388
	 * 4. save the record into database. If this fails, it will skip the rest of the steps;
	 * 5. call [[afterSave()]];
Qiang Xue committed
389
	 *
390
	 * In the above step 1, 2, 3 and 5, events [[EVENT_BEFORE_VALIDATE]],
Qiang Xue committed
391 392
	 * [[EVENT_BEFORE_UPDATE]], [[EVENT_AFTER_UPDATE]] and [[EVENT_AFTER_VALIDATE]]
	 * will be raised by the corresponding methods.
Qiang Xue committed
393 394 395 396 397 398 399 400 401 402 403 404
	 *
	 * Only the [[changedAttributes|changed attribute values]] will be saved into database.
	 *
	 * For example, to update a customer record:
	 *
	 * ~~~
	 * $customer = Customer::find($id);
	 * $customer->name = $name;
	 * $customer->email = $email;
	 * $customer->update();
	 * ~~~
	 *
405 406 407 408 409 410 411 412 413 414 415 416
	 * Note that it is possible the update does not affect any row in the table.
	 * In this case, this method will return 0. For this reason, you should use the following
	 * code to check if update() is successful or not:
	 *
	 * ~~~
	 * if ($this->update() !== false) {
	 *     // update successful
	 * } else {
	 *     // update failed
	 * }
	 * ~~~
	 *
Qiang Xue committed
417 418
	 * @param boolean $runValidation whether to perform validation before saving the record.
	 * If the validation fails, the record will not be inserted into the database.
Qiang Xue committed
419 420
	 * @param array $attributes list of attributes that need to be saved. Defaults to null,
	 * meaning all attributes that are loaded from DB will be saved.
421 422
	 * @return integer|boolean the number of rows affected, or false if validation fails
	 * or [[beforeSave()]] stops the updating process.
423
	 * @throws StaleObjectException if [[optimisticLock|optimistic locking]] is enabled and the data
424
	 * being updated is outdated.
425
	 * @throws \Exception in case update failed.
Qiang Xue committed
426
	 */
Qiang Xue committed
427
	public function update($runValidation = true, $attributes = null)
Qiang Xue committed
428
	{
429
		if ($runValidation && !$this->validate($attributes)) {
Qiang Xue committed
430 431
			return false;
		}
432
		$db = static::getDb();
Qiang Xue committed
433 434 435 436
		if ($this->isTransactional(self::OP_UPDATE) && $db->getTransaction() === null) {
			$transaction = $db->beginTransaction();
			try {
				$result = $this->updateInternal($attributes);
resurtm committed
437
				if ($result === false) {
438 439 440
					$transaction->rollback();
				} else {
					$transaction->commit();
441
				}
Qiang Xue committed
442
			} catch (\Exception $e) {
443
				$transaction->rollback();
Qiang Xue committed
444
				throw $e;
445
			}
Qiang Xue committed
446 447
		} else {
			$result = $this->updateInternal($attributes);
448 449 450
		}
		return $result;
	}
451

Qiang Xue committed
452
	/**
Qiang Xue committed
453 454 455 456 457 458 459 460 461
	 * Deletes the table row corresponding to this active record.
	 *
	 * This method performs the following steps in order:
	 *
	 * 1. call [[beforeDelete()]]. If the method returns false, it will skip the
	 *    rest of the steps;
	 * 2. delete the record from the database;
	 * 3. call [[afterDelete()]].
	 *
Qiang Xue committed
462
	 * In the above step 1 and 3, events named [[EVENT_BEFORE_DELETE]] and [[EVENT_AFTER_DELETE]]
Qiang Xue committed
463 464
	 * will be raised by the corresponding methods.
	 *
465 466
	 * @return integer|boolean the number of rows deleted, or false if the deletion is unsuccessful for some reason.
	 * Note that it is possible the number of rows deleted is 0, even though the deletion execution is successful.
467
	 * @throws StaleObjectException if [[optimisticLock|optimistic locking]] is enabled and the data
468
	 * being deleted is outdated.
469
	 * @throws \Exception in case delete failed.
Qiang Xue committed
470 471 472
	 */
	public function delete()
	{
473
		$db = static::getDb();
474
		$transaction = $this->isTransactional(self::OP_DELETE) && $db->getTransaction() === null ? $db->beginTransaction() : null;
475 476 477 478 479 480 481
		try {
			$result = false;
			if ($this->beforeDelete()) {
				// we do not check the return value of deleteAll() because it's possible
				// the record is already deleted in the database and thus the method will return 0
				$condition = $this->getOldPrimaryKey(true);
				$lock = $this->optimisticLock();
resurtm committed
482
				if ($lock !== null) {
483 484 485
					$condition[$lock] = $this->$lock;
				}
				$result = $this->deleteAll($condition);
resurtm committed
486
				if ($lock !== null && !$result) {
487 488
					throw new StaleObjectException('The object being deleted is outdated.');
				}
489
				$this->setOldAttributes(null);
490
				$this->afterDelete();
491
			}
resurtm committed
492 493
			if ($transaction !== null) {
				if ($result === false) {
494 495 496 497
					$transaction->rollback();
				} else {
					$transaction->commit();
				}
498
			}
499
		} catch (\Exception $e) {
resurtm committed
500
			if ($transaction !== null) {
501 502 503
				$transaction->rollback();
			}
			throw $e;
Qiang Xue committed
504
		}
505
		return $result;
w  
Qiang Xue committed
506 507 508
	}

	/**
Qiang Xue committed
509 510
	 * Returns a value indicating whether the given active record is the same as the current one.
	 * The comparison is made by comparing the table names and the primary key values of the two active records.
511
	 * If one of the records [[isNewRecord|is new]] they are also considered not equal.
Qiang Xue committed
512
	 * @param ActiveRecord $record record to compare to
Qiang Xue committed
513
	 * @return boolean whether the two active records refer to the same row in the same database table.
w  
Qiang Xue committed
514
	 */
Qiang Xue committed
515
	public function equals($record)
w  
Qiang Xue committed
516
	{
517 518 519
		if ($this->isNewRecord || $record->isNewRecord) {
			return false;
		}
Qiang Xue committed
520
		return $this->tableName() === $record->tableName() && $this->getPrimaryKey() === $record->getPrimaryKey();
w  
Qiang Xue committed
521 522
	}

523
	/**
524 525 526
	 * Returns a value indicating whether the specified operation is transactional in the current [[scenario]].
	 * @param integer $operation the operation to check. Possible values are [[OP_INSERT]], [[OP_UPDATE]] and [[OP_DELETE]].
	 * @return boolean whether the specified operation is transactional in the current [[scenario]].
527
	 */
528
	public function isTransactional($operation)
529 530
	{
		$scenario = $this->getScenario();
531 532
		$transactions = $this->transactions();
		return isset($transactions[$scenario]) && ($transactions[$scenario] & $operation);
533
	}
w  
Qiang Xue committed
534
}