Answer the question
In order to leave comments, you need to log in
Why are records duplicated in the database (ActiveRecord, Yii2)?
Greetings. I have been looking at these 6 lines for a couple of hours now. That's all there is in the action. When executed, 2 identical records are created in the database with different id (auto-increment).
Here is the action code:
public function actionIndex()
{
$draftOrder = new OrdersDraft();
$draftOrder->castomer_id = 22;
$draftOrder->title = "Черновик заказа " . date("d.m.y H:i:s", time());
$draftOrder->status_id = 1;
$draftOrder->date_add = time();
$draftOrder->save();
}
namespace common\models;
use Yii;
class OrdersDraft extends \yii\db\ActiveRecord
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'orders';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['castomer_id', 'title', 'status_id', 'date_add'], 'required'],
[['castomer_id', 'status_id', 'date_add'], 'integer'],
[['title'], 'string', 'max' => 150],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'castomer_id' => 'Castomer ID',
'city' => 'Город',
'category_id' => 'Category ID',
'title' => 'Заголовок',
'price_min' => 'Мин. цена',
'price_max' => 'Макс. цена',
'description' => 'Описание',
'delivery' => 'Доставка',
'deadline' => 'Актуально до',
'status_id' => 'Статус',
'date_add' => 'Добавлен',
];
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question