Updated validation for the project

This commit is contained in:
iIronside 2023-10-13 15:44:16 +03:00
parent e712f2fc36
commit b004f6e21b
2 changed files with 34 additions and 2 deletions

View File

@ -23,6 +23,7 @@ use yii\helpers\ArrayHelper;
* *
* @property FieldsValue[] $fieldsValues * @property FieldsValue[] $fieldsValues
* @property Company $company * @property Company $company
* @property User $owner
* @property ProjectUser[] $projectUsers * @property ProjectUser[] $projectUsers
* @property Mark[] $mark * @property Mark[] $mark
* @property MarkEntity[] $markEntity * @property MarkEntity[] $markEntity
@ -55,8 +56,8 @@ class Project extends \yii\db\ActiveRecord
public function rules() public function rules()
{ {
return [ return [
['name', 'unique'], [['name', 'owner_id', 'status'], 'required'],
[['name', 'status'], 'required'], [['owner_id', 'name'], 'unique', 'targetAttribute' => ['owner_id', 'name']],
[['description'], 'string'], [['description'], 'string'],
[['created_at', 'updated_at'], 'safe'], [['created_at', 'updated_at'], 'safe'],
[['status'], 'exist', 'skipOnError' => true, 'targetClass' => Status::class, 'targetAttribute' => ['status' => 'id']], [['status'], 'exist', 'skipOnError' => true, 'targetClass' => Status::class, 'targetAttribute' => ['status' => 'id']],

View File

@ -0,0 +1,31 @@
<?php
use yii\db\Migration;
/**
* Class m231013_122324_add_foreign_key_in_project_from_owner_id_to_user_id
*/
class m231013_122324_add_foreign_key_in_project_from_owner_id_to_user_id extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->addForeignKey(
'project_user',
'project',
'owner_id',
'user',
'id'
);
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropForeignKey('project_user', 'project');
}
}