/** * 通过company_id 关联legal_company表 */ public function getLegalCompany() { return $this->hasOne ( LegalCompanyModel::className (), [ 'company_id' => 'company_id' ] )->onCondition(['legal_company.is_valid'=>VALID]); }
$condition=[ 'WITH'=>[ 'legalCompany' ], 'SELECT'=>[ 'company.company_id', 'legal_company.open_type','legal_company.legal_purchase'], 'EQ#company.is_valid' => VALID, 'EQ#company.company_id'=>1 ]; $row=(new CompanyModel ())->findRow ( $condition );