/** * @param array $types * @return bool * @throws CDbException */ public function setTypes(array $types) { $transaction = Yii::app()->getDb()->beginTransaction(); try { TypeAttribute::model()->deleteAll('attribute_id = :attribute', [':attribute' => $this->id]); foreach ($types as $type) { $attribute = new TypeAttribute(); $attribute->setAttributes(['attribute_id' => $this->id, 'type_id' => (int) $type]); $attribute->save(); } $transaction->commit(); return true; } catch (Exception $e) { $transaction->rollback(); return false; } }