Reputation: 11
How can run this query on yii by using CActiveDataProvider.
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 employers re on co.id = re.company_id limit 20;
Recruiter relation
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'), ); }
Companies relations
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 relations
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( ); }
Upvotes: 1
Views: 1262
Reputation: 714
use this method may help you ;) your code is so big for attection ..Write a simplest part ...
$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->....
}
Upvotes: 2