Answer the question
In order to leave comments, you need to log in
Insert() ActiveRecord MongoDB not working. Why?
Connecting to mongo and fetching works, adding a document via migration works, but not via ActiveRecord.
Active Record Model
<?php
namespace common\models\activeRecord\searchPhone;
use Yii;
/**
* This is the model class for collection "search_phone".
*
* @property \MongoDB\BSON\ObjectID|string $_id
* @property mixed $name
* @property mixed $birth
* @property mixed $full_name
*/
class SearchPhone extends \yii\mongodb\ActiveRecord
{
/**
* {@inheritdoc}
*/
public static function collectionName()
{
return ['mydb', 'search_phone'];
}
/**
* {@inheritdoc}
*/
public function attributes()
{
return [
'_id',
'phone',
'name',
'bitrh',
'full_name',
];
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['name', 'bitrh', 'full_name'], 'safe']
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'_id' => 'ID',
'name' => 'Name',
'bitrh' => 'Bitrh',
'full_name' => 'Full Name',
];
}
}
/**
* @throws \Exception
*/
public function getModelSearchPhone()
{
/**
* @var $model \common\models\localRecord\searchPhone\SearchPhone
*/
$model = new $this->search_phone();
$model->insert(['name'=> 'alex','phone'=> '79898707217','birth'=> 3124523143,'full_name'=> 'alex alex']);
}
Answer the question
In order to leave comments, you need to log in
you don't have a phone field in your rules() model , so the insert request doesn't validate
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question