1

如何使用 CActiveDataProvider 在 yii 上运行此查询。

select co.name,re.company_id,re.person_name,re.last_login_at, (select count(*) from activity_logs ac where re.id = ac.user_id ) as count from Companies co inner join employees re on 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(
  );
}
4

1 回答 1

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->....
}
于 2013-07-22T17:48:13.680 回答