Problem With Scope

I have a small user console that allows the user to only see their account.

When invoking the url to the console without being logged in (user_id is not set)


I was getting an error like the following:


CDbCommand failed to execute the SQL statement: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIMIT 1' at line 1. The SQL statement executed was: [b]SELECT * FROM `demandpartner` `t` WHERE acct_id= LIMIT 1 [/b]

My Controller:


class DemandpartnerController extends Controller {

    public function actionConsole() {	

	$model= $this->loadModel();

	$this->render('console', array(

                'model' => $model,



  public function loadModel() {

	[b]if isset(myAccount()) {[/b]  /* I added this to catch error */ 

	  $model= Demandpartner::model()->myAccount()->find(); 


                    throw new CHttpException(404,Yii::t('app', 'The requested page does not exist.'));

            return $model;





My Model has a Scope as follows:

	public function scopes()


        return array(




Is there a more graceful way to deal with this?

Would not $model= Demandpartner::model()->myAccount()->find(); be null if the scope is not set?

Should I test for myAccount or to be set ?



if isset(myAccount())

I’ve never testetd this. Does this work ?

I think so. Maybe something like:

if(!Yii::app()->user->isGuest) $model= Demandpartner::model()->myAccount()->find(); 

Thanks Luc - I will give it a shot.

I am still playing with the whole security issue. If the user is not logged in, it just should go to a 404 error I guess.