I have this multi tenant app. Tenants, which i use to separate the data, can have many projects. In order to separate the data, i have created a default scope on every model where
public function defaultScope()
{
return array(
'condition'=>'tenant_id='.Yii::App()->user->tenantId
);
}
A project can have risks, issues, team members, etc… Now when i select a project, i store the project id in a session. I use this to retrieve, via default scope, the risks, issues… that relate to the project
public function defaultScope()
{
return array(
'condition'=>'project_id='.Yii::App()->user->projectId
.' and tenant_id='.Yii::App()->user->tenantId
);
}
In a dashboard type view, I want to display latest risks and issues entered. But if i have not chosen/clicked on a project, i have no project id value stored for the session and i get an error because of the default scope. How can i get around this?