CActiveDataProvider Column Not Found When Scoped to Table

This seems like it should be something pretty obvious, but I’m not able to see it.

Here’s the situation - I have two tables. One table contains different devices that are added in a certain area, and the other table contains devices that are “registered” in the system. Basically, I need to make sure that each device in one table is in another table. If it isn’t, it needs to be flagged/marked visually somehow.

My first thought was to create a HAS_ONE relation between the table:



	 * @return array relational rules.


	public function relations()


		// NOTE: you may need to adjust the relation name and the related

		// class name for the relations automatically generated below.

		return array(

            'location' => array( self::HAS_ONE, 'location', 'username' ),



The goal of this relation is to say that each individual should have an entry in the location table.

I then modified my Active Record to account for this:

       $dp = new CActiveDataProvider( 'subscriber', array(

                'criteria' => array(

                    'with' => array(

                        'location' => array(

                            'location.domain = :site',



                    'condition' => 'subscriber.domain = :site',

                    'params' => array( ':site' => $this->_site . "" ),




Both tables have a domain column to match up certain areas. The problem is that when I attempt to make the condition "subscriber.domain = :site" I run into issues:

CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'subscriber.domain' in 'where clause'

I know for a fact that subscriber has a domain column. This CActiveRecord will also work fine without trying to account for the information in the “with” section. I’m also pretty new and kinda confused by relations. Any ideas on why this may be the case? Also, thinking about it now, I think there might be a better way to handle this issue if anyone has any ideas.

Thanks in advance!

You should try

'condition' => 't.domain = :site',

I’m not sure about CActiveDataProvider, but in general the primary table alias has to be ‘t’.

See the section "Disambiguating Column Names" in the following guide chapter