Relation Table Not in Query

I have a query in which the “with” table is not being included, and I’m not sure why. Here is my model relation (Message):


public function relations() {


	  array (

			 'recipients' => array( self::HAS_MANY,   'MessageRecipient',  'message_id' ),



and here is my controller code:

        $provider = new CActiveDataProvider('Message',


                'criteria' => array(

                    'condition' => "recipients.recipient_id=42",

                    'order'     => 'created DESC',

                    'with'      => array('recipients'),


                'pagination' => array('pageSize' => self::PAGE_SIZE)



I am getting this error:

CDbCommand failed to execute the SQL statement: SQLSTATE[42P01]: 

Undefined table: 7 ERROR: missing FROM-clause entry for table "recipients" at character 486 

The recipients table is not being included in the query, for some reason, so it can’t be referenced. Is it because of the HAS_MANY relation and/or lazy loading? Is there a way I can force the query to include that table, perhaps some qualification of the relation or the “with” that I’m missing?

Thanks in advance for any assistance.


I think you should set together=>true in your relation.

'recipients' => array( self::HAS_MANY,   'MessageRecipient',  'message_id', 'together'=>true ),



Thanks, Giovanni, but I had tried that one and it didn’t help.