If you want to have one SQL query don't forget to use method together()
For more information please look at note in
guide.
$criteria->condition='group_id:group_id';
$criteria->params=array(':group_id'=>2);
$model=User::model()->with('users')->together()->findAll($criteria)
If you want to see how is you query looking like add following to application configuration
/* logging feature */
'components'=>array(
'log'=>array(
'class'=>'CLogRouter',
'routes'=>array(
array(
'class'=>'CFileLogRoute',
'levels'=>'error, warning',
),
array(
'class'=>'CWebLogRoute',
),
),
),
'db'=>array(
'connectionString' => 'mysql:host=localhost;dbname=xxx',
'username' => 'xxx',
'password' => 'xxx',
'charset' => 'utf8',
'enableParamLogging' => true, /* turn on logging sql statements */
),
)
I'm not complete idiot... some parts are missing!