如何使用CActiveDataProvider在yii上运行此查询。
选择co.name,re.company_id,re.person_name,re.last_login_at,(选择 count(*)来自activity_logs ac,其中re.id = ac.user_id)作为计数 来自公司内部加入雇主重新加入co.id = re.company_id 限制20;
招聘人员关系
public function relations() { // NOTE: you may need to adjust the relation name and the related // class name for the relations automatically generated below. return array( 'candidatesEmployers' => array(self::HAS_MANY, 'CandidatesEmployers', 'employer_id'), 'employerCandidateActivities' => array(self::HAS_MANY, 'EmployerCandidateActivities', 'employer_id'), 'city' => array(self::BELONGS_TO, 'Cities', 'city_id'), 'company' => array(self::BELONGS_TO, 'Companies', 'company_id'), 'interviews' => array(self::HAS_MANY, 'Interviews', 'employer_id'), 'jobs' => array(self::HAS_MANY, 'Jobs', 'employer_id'), ); }
公司关系
public function relations() { // NOTE: you may need to adjust the relation name and the related // class name for the relations automatically generated below. return array( 'city' => array(self::BELONGS_TO, 'Cities', 'city_id'), 'employers' => array(self::HAS_MANY, 'Employers', 'company_id'), ); }
ActivityLogs关系
public function relations() { // NOTE: you may need to adjust the relation name and the related // class name for the relations automatically generated below. return array( ); }
答案 0 :(得分:2)
使用此方法可能对您有帮助;) 你的代码对于考试来说是如此之大..写一个最简单的部分......
$topRage=new CDbCriteria();
$topRage->select="*";
$topRage->alias="re";
$topRage->order="rateing DESC";
$topRage->join='JOIN co ON co.id = re.company_id';
$topRage->limit="20";
$my = yourMODELnAME::model()->findAll($topRage);
foreach($my as $a){
echo $a->....
}