/** * Delete relations * @return bool */ public function cleanUpRelations() { if (!is_subclass_of($this->owner, '\\yii\\db\\ActiveRecord')) { return false; } if (isset($this->owner->is_deleted) && 0 === intval($this->owner->is_deleted)) { return false; } if (null === ($object = Object::getForClass($this->owner->className()))) { return false; } $whereDelete = ['object_id' => $object->id, 'object_model_id' => $this->owner->id]; ObjectPropertyGroup::deleteAll($whereDelete); ObjectStaticValues::deleteAll($whereDelete); Image::deleteAll($whereDelete); ViewObject::deleteAll($whereDelete); try { Yii::$app->db->createCommand()->delete($object->categories_table_name, ['object_model_id' => $this->owner->id])->execute(); Yii::$app->db->createCommand()->delete($object->column_properties_table_name, ['object_model_id' => $this->owner->id])->execute(); Yii::$app->db->createCommand()->delete($object->eav_table_name, ['object_model_id' => $this->owner->id])->execute(); } catch (Exception $e) { // do nothing } return true; }