public function afterInsert() { $data = \Yii::$app->request->post($this->owner->formName()); if (!isset($data[static::$formName]) || empty($data[static::$formName])) { return; } $indexs = []; $modelClass = $this->getEntityClass(); foreach ($data[static::$formName] as $id) { $indexs[] = [$modelClass, $this->getEntityId(), $id]; } if (count($indexs)) { \Yii::$app->db->createCommand()->batchInsert(TaxonomyIndex::tableName(), ['entity', 'entity_id', 'taxonomy_id'], $indexs)->execute(); } }