defaultScope question

I’m trying to fix old projects that have been affected by the SQL db alias change noted here

But defaultScope doesn’t seem to do what I expect it to in all cases.

I am getting:

CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found:

1054 Unknown column '' in 'on clause'

Here’s the start of the Model with the defaultScope as I understand it should be :

class Tag extends CActiveRecord {

  public static function model($className=__CLASS__) { return parent::model($className); }

  public function tableName()	{ return 'Tag'; }

  public function defaultScope() {

    return array(

      'alias' => 'Tag',




And later in the same class I call the following, which generates the error:

public function findTagWeights($limit = 20) {

  $criteria = new CDbCriteria(array(

    'select'	=> 'name, COUNT(postId) as weight',

    'join'		=> 'INNER JOIN PostTag ON = PostTag.tagId',

    'group'		=> 'name',

    'having'	=> 'COUNT(postId) > 0',

    'order'		=> 'weight DESC',

    'limit'		=> $limit


  $rows = $this->dbConnection->commandBuilder->createFindCommand($this->tableSchema, $criteria)->queryAll();

If I change to, all works. I don’t understand why. Please educate me. Thanks.

Spike this. AR relations behaviour has changed. The error was in the related class.