есть класс Phone он организует сохранение в базу MongoBD вот так огранизовано сохранение
class Phone extends ActiveRecord
{
public $contact_collection_id;
public $phone;
public $clients_id;
public $username;
public static function collectionName()
{
return 'phone';
}
/**
* @param int $contact_collection_id
* @param int $phone
* @param int $clients_id
* @param string $username
*/
public static function createPhone(int $contact_collection_id,int $phone, int $clients_id,string $username){
$phones = new static();
$phones->contact_collection_id=$contact_collection_id;
$phones->phone=$phone;
$phones->clients_id=$clients_id;
$phones->username=$username;
return $phones;
}
...
}
class PhoneFormCreateService
{
public function create(PhoneCreateForm $phoneCreateForm){
$array=['+','(',')','-'];
if(Phone::find()->where(['phone'=>$phoneCreateForm->phone,'contact_collection_id'=>$phoneCreateForm->contact_collection_id])->one())
throw new \RuntimeException('Phone already exist');
$phone=Phone::createPhone(
$phoneCreateForm->contact_collection_id,
(int)str_replace($array,'',$phoneCreateForm->phone),
$phoneCreateForm->clients_id,
$phoneCreateForm->username
);
if(!$phone->save())
throw new \RuntimeException(json_encode($phone->errors));
return $phone;
}
}
в общем итоге в debug-ере получаю вот так
viber.phone.bulkWrite([{"type":"insert","document":[]}])
Подскажите что я делаю не так ?