[SOLVED] Problem with alias in Active Record relations

In my controller, I'm doing:

$products = Product::model()->with('brandobj')->together()->findAll();

Here is the relations() in my Product model:

public function relations() {


        return array(


            'brandobj' => array(self::BELONGS_TO, 'alias'=>'brandAlias', 'Brand', 'brand'),


        );


    }


}

The Brand model is just a basic model.  The problem is that when I define an alias, I get the following error:

Property "CBelongsToRelation.0" is not defined.

And the stack trace:

#0 /var/www/axion/framework/db/ar/CActiveRecord.php(1844): CComponent->__set('0', 'brand')


#1 /var/www/axion/framework/db/ar/CActiveRecord.php(2153): CBaseActiveRelation->__construct('brandobj', 'Brand', 'brand', Array)


#2 /var/www/axion/framework/db/ar/CActiveRecord.php(634): CActiveRecordMetaData->__construct(Object(Product))


#3 /var/www/axion/app/modules/admin/modules/ecommerce/models/Product.php(11): CActiveRecord::model('Product')


#4 /var/www/axion/app/controllers/store/CategoryController.php(39): Product::model()


#5 /var/www/axion/framework/web/CController.php(262): CategoryController->missingAction('mens-shoes')


#6 /var/www/axion/framework/web/CWebApplication.php(332): CController->run('mens-shoes')


#7 /var/www/axion/framework/web/CWebApplication.php(120): CWebApplication->runController('store/category/...')


#8 /var/www/axion/framework/base/CApplication.php(133): CWebApplication->processRequest()


#9 /var/www/axion/index.php(20): CApplication->run()


#10 {main}

This works completely normal when used without an alias defined in relations().  Is there something that I am missing?

Try moving the alias definition to the end of the array like mentioned here:

http://www.yiiframew…elations-detail

specifically:



'varName'=>array('relationType', 'className', 'foreignKey', ...additional options)


Worked perfectly, thanks!