I would like to Yii:afi my application with a nice relation.

Today i have this SQL:

SELECT hours,date FROM tbl_day INNER JOIN tbl_user ON WHERE tbl_user.companyId=".Yii::app()->user->companyId

I have treid to manage this SQL into a relation statment in my Company model but cant figure it out.

Its three tables, Company, Users and Days.

Company has many Users

Users has many Days

I have tried in my company model MANY_MANY and HAS_MANY but cant figure it out, any idees?

I think the problem can be that tbl_day.userId and tbl_user.companyId not is a PK. Only is a PK.



In company controller:

‘users’ => array(self::HAS_MANY, ‘User’, ‘companyId’,‘condition’=>‘open=1’),

‘days’ => array(self::HAS_MANY, ‘Day’, array(‘id’=>‘userId’), ‘through’ => ‘users’),