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),
* )
* }
* )
*/