ActiveRecord 這個class檔案update方法裡面如何下:
public function update($runValidation = true, $attributeNames = null)
{ if ($runValidation && !$this->validate($attributeNames)) { Yii::info('Model not updated due to validation error.', __METHOD__); return false; } if (!$this->isTransactional(self::OP_UPDATE)) { return $this->updateInternal($attributeNames); } $transaction = static::getDb()->beginTransaction(); try { $result = $this->updateInternal($attributeNames); if ($result === false) { $transaction->rollBack(); } else { $transaction->commit(); } return $result; } catch (\Exception $e) { $transaction->rollBack(); throw $e; }}
為什麼update底層也用了事務操作,如果在外面也開啟事務,事務嵌套,會造成什麼影響?
回複內容:
ActiveRecord 這個class檔案update方法裡面如何下:
public function update($runValidation = true, $attributeNames = null)
{ if ($runValidation && !$this->validate($attributeNames)) { Yii::info('Model not updated due to validation error.', __METHOD__); return false; } if (!$this->isTransactional(self::OP_UPDATE)) { return $this->updateInternal($attributeNames); } $transaction = static::getDb()->beginTransaction(); try { $result = $this->updateInternal($attributeNames); if ($result === false) { $transaction->rollBack(); } else { $transaction->commit(); } return $result; } catch (\Exception $e) { $transaction->rollBack(); throw $e; }}
為什麼update底層也用了事務操作,如果在外面也開啟事務,事務嵌套,會造成什麼影響?