Problem findAll() using limit and HAS_MANY relation

I found following errors.

In blog demo example database, it occurs when using limit and HAS_MANY join.

class TestController extends Controller


	public function actionIndex()


    $criteria = new CDbCriteria(

              array( 'with' => array('comments') ) 


    $criteria->compare('', 'Tester', false);


    $criteria->limit = 10;  // It works if delete this line

    $result = Post::model()->findAll($criteria);




Error message:

CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column ‘’ in ‘where clause’

operating system: Mac OS X snow leopard

Web server: Apache 2.2.16

browser type: Google Chrome

Yii version: Yii 1.1.4.r2429

Please any help.

You need to join the ‘comments’ relation.

Either try

$result = Post::model()->with('comments')->findAll($criteria);

or set the with option in your criteria:



Ooops, i’m sorry, you already have set it. So it should be the together option of the criteria. Try setting it to true.