/**
  * beforeSave
  *
  * Sets up the transaction and triggers relation parsing
  *
  * @param (Object) (event) the active record event
  *
  * @return (Bool) the result of calling the parent beforeSave($event)
  */
 public function beforeSave($event)
 {
     // ensure transactions
     if ($this->useTransaction && $this->owner->dbConnection->currentTransaction === null) {
         $this->setTransaction($this->owner->dbConnection->beginTransaction());
     }
     $this->preSaveHelper($this->owner);
     return parent::beforeSave($event);
 }
 /**
  * Tests the transaction getter and setter
  */
 public function testGetSetTransaction()
 {
     $behavior = new \EActiveRecordRelationBehavior();
     $behavior->setTransaction($transaction = \Yii::app()->db->beginTransaction());
     $this->assertInstanceOf('CDbTransaction', $transaction);
     $this->assertSame($transaction, $behavior->getTransaction());
 }