HEX
Server: LiteSpeed
System: Linux premium260.web-hosting.com 4.18.0-553.45.1.lve.el8.x86_64 #1 SMP Wed Mar 26 12:08:09 UTC 2025 x86_64
User: aliazzsr (627)
PHP: 7.4.33
Disabled: NONE
Upload Files
File: //home/aliazzsr/api.crm.vqode.com/models/core/ProjectContact.php
<?php
namespace app\models\core;

use app\components\BaseModel;

class ProjectContact extends BaseModel
{
    public static function tableName()
    {
        return 'project_contact';
    }

    public function rules()
    {
        return [
            [['contact_id', 'project_id',], 'required'],
            [['contact_id'], 'unique', 'targetAttribute' => ['contact_id', 'project_id'],
                'message' => 'This contact has been already bonded to the project.'],
            [['contact_id'], 'exist', 'targetClass' => CompanyContact::className(), 'targetAttribute' => 'id'],
            [['project_id'], 'exist', 'targetClass' => Project::className(), 'targetAttribute' => 'id'],
        ];
    }

    public static $extraFields = [
        'companyContact',
        'project',
    ];

    public static function findWithJoin()
    {
        return parent::find()
            ->joinWith([
                'companyContact as companyContact',
                'project as project',
            ]);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getCompanyContact()
    {
        return $this->hasOne(CompanyContact::className(), ['id' => 'company_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getProject()
    {
        return $this->hasOne(Project::className(), ['id' => 'project_id']);
    }
}
/**
 * @SWG\Definition(
 *     definition="ProjectContact",
 *     type="object",
 *     description="ProjectContact model, M2M relation between CompanyContact and Project models",
 *     allOf={
 *       @SWG\Schema(
 *           @SWG\Property(property="id", type="integer", example=7),
 *           @SWG\Property(property="contact_id", type="integer", example=8),
 *           @SWG\Property(property="project_id", type="integer", example=4),
 *       )
 *     }
 * )
 */