I’ve got a bit of a confusing problem that I’d like your advice on.
I’ve got two models:
-
Site
-
SiteSurvey
I’ve also got a CSTAT relationship in Site that counts my SiteSurveys.
'surveyCount' => array(self::STAT, 'Survey', 'siteId',
'with'=>'site',
),
So far so good. SurveyCount is properly populated, I can print out the number of surveys and it’s accurate.
In addition, I’ve got a defaultScope in SiteSurvey that checks to make sure the user is only able to view site surveys for sites the user is allowed to view:
// SiteSurvey.php
public function defaultScope() {
if(Yii::app()->user->isSubUser())
{
return array(
'condition'=>'site.type = :type',
'params'=>array(':type'=>Yii::app()->user->siteType),
'with'=>'site',
);
}
else return array();
}
This code works fine if looking at a SiteSurvey grid as a sub user. And my surveyCount works great if an admin user looks at a site grid and looks at information about site surveyCounts. But if I look at a site grid as a subUser, I get the following error:
It looks like the CSTAT relationship isn’t honoring the defaultScope with parameter that I specified. Is that accurate? Any suggestions on ways I might be able to handle this?
Thanks