public function addCountry(AreaAddCountryEvent $event) { $countryIds = $event->getCountryId(); $areaId = $event->getAreaId(); foreach ($countryIds as $countryId) { if (null !== ($country = CountryQuery::create()->findPk($countryId))) { $country->setDispatcher($event->getDispatcher()); $country->setAreaId($areaId)->save(); } } $event->setArea(AreaQuery::create()->findPk($areaId)); }