Yii Framework Forum: CActiveDataProvider Column Not Found When Scoped to Table - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

CActiveDataProvider Column Not Found When Scoped to Table Rate Topic: -----

#1 User is offline   Doug Swain 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 12
  • Joined: 28-December 09

Posted 10 April 2010 - 02:42 PM

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:

subscriber:
	/**
	 * @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 . ".defero3.net" ),
                ),
            )
        );


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!
0

#2 User is online   tri 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,677
  • Joined: 20-November 08
  • Location:Stockholm, Sweden

Posted 10 April 2010 - 03:43 PM

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
http://www.yiiframew...de/database.arr

/Tommy
Don't forget to read The Definitive Guide to Yii (1.1 en) (1.1 sv) (2.0 en) | The class reference (1.1) (2.0) has the details
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users