Hi All,
I have 3 tables and need to generate this query with CActiveDataProvider.
select companies.name,employers.company_id,employers.person_name,employers.last_login_at,
(select count(*) from activity_logs where employers.id = activity_logs.user_id ) as count
from companies inner join employers on
companies.id = employers.company_id;
Recruiter(employers) Model 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 Model 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 Model relations
/**
* @return array relational rules.
*/
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(
);
}
The activity logs tables related in activity_logs.user_id as fk to employer.id
How can generate this query and run in view as zii.widgets.CListView.