like all records from company_user + username from user table
in user model i have written this type of 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(
'company_user' =>array(self::HAS_ONE,'CompanyUser','user_id','select' =>array('first_name','status'),
'with'=>array('company'=>array(self::BELONGS_TO, 'Company', 'company_id','joinType' => 'INNER JOIN')),
),
'company_user_rel_only' =>array(self::HAS_ONE,'CompanyUser','user_id','select' =>array('first_name', 'last_name')),
}
I don’t know if it will help you, but if your database model seems ok to you (with foreign key constraint, …), you just have to generate your Yii model with gii, then you will be sure the Yii relations are corrects.