I’ve been able to define the relations.
However I’ve come up with another issue…
My model/table has composite primary key (CountryId and CompanyId).
I’ve declared a default scope which ensures I only get teh countries for a given company and it works on the index action.
public function defaultScope()
{
return array(‘condition’ => “CompanyId=” . Yii::app()->user->getState(‘cmpId’));
}
But if I try to view a specific country I get some errors. It seems yii for some reason is demanding the two primary keys in my url. But I only want to give the CountryId in the url and let the scope handle the second primary key.
First I got some 400 - your request is invalid. I fixed this by changing the action to:
public function actionView(array $id)
{
$this->render(‘view’,array(‘model’=>$this->loadModel($id),));
}
So now it works if both primary keys are included.
But, how can i make it work with only one primary key included?
I’ve tried to implement the following code in the model with no luck
public function actionView(array $id)
{
$this->render(‘view’,array(‘model’=>$this->loadModel($id),));
}
public function actionView(array $id)
{
$this->render(‘view’,array(‘model’=>$this->loadModel($id),));
}
Any clues on what I should do?
Change loadModel in my controller
public function loadModel($id)
{
$model = AddressCountry::model()->findByPk(array($id[‘CountryId’], Yii::app()->user->getState(‘cmpId’, 0)));
Which only result in the following error message
The value for the column "CountryId" is not supplied when querying the table "AddressCountry".