* @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.
'crawlers' => array(self::HAS_MANY, 'UserCrawler', 'user_id'),
'crawlersCount' => array(self::STAT, 'UserCrawler', 'user_id'),
'user_groups'=>array(self::MANY_MANY, 'Group', 'user_group(user_id, group_id)'),
'groups'=>array(self::HAS_MANY, 'UserGroup', 'user_id'),
This is the search function:
public function searchGroup( $groupID, $inGroup )
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria->with = array('groups');
if ( $inGroup ) $criteria->addCondition('groups.group_id!='.$groupID);
return new CActiveDataProvider('User', array(
This is the error:
CDbCommand ha riportato un errore nell’esecuzione della query SQL: SQLSTATE[42S22]: Column not found: 1054 Unknown column ‘groups.group_id’ in ‘where clause’
It looks like your relations are backwards. The ‘groups’ relation points to the UserGroup table and the ‘user_groups’ relation points to the Groups table. So, when you do CDbCriteria with(‘groups’) you’re including the UserGroups table. That’s why your conditions, which reference ‘groups.group_id’ aren’t working.
This is what it says when the secondary table is not being joined properly. In this case, it appears the groups table is not being joined in, so it defaults to assuming you are looking for a column within the main table.
When you say $criteria->with = array(‘groups’), what this does is grabs the relationship that you labeled as “groups” which according to what you have shown is actually for the UserGroups table, not the Groups table as you seem to require. This is what I was saying originally. You should have labeled your relationships differently.