AR witch() and sort()




model Project:

/**

* @var string $title

*/

public function relations()

{

 return array(

   'client' => array(self::BELONGS_TO, 'Client', 'clientid', 'alias'=>'client')

 );

}


model Client:

/**

* @var string $title

*/

public function relations()

{

 return array(

  'projects' => array(self::HAS_MANY, 'Project', 'clientid'),

 );

}

ProjectController:

public function actionList(){

  $criteria=new CDbCriteria;

....

  $csattr=array_keys(Project::model()->getAttributes());

  $csattr['client.title']='clientTitle';

  $sort=new CSort('Project');

  $sort->attributes = $csattr;

  $sort->applyOrder($criteria);


// THE IS ERROR:

$models=Project::model()->with(array('client'))->findAll($criteria);

//$models=Project::model()->findAll($criteria);

}



And on call findAll have SQL error:




Ambiguous column: 7 ERROR: relation to column "title" is ambiguous 

LINE 1: ...nt ON ("Project"."clientid"=client."id") ORDER BY "title", "...



[b]How to set up Csort for use table aliases ?

Or maybe i have error in code ?

[/b]

For now i use this dirty method:




unset($csattr['title']);

$csattr=array_keys(Project::model()->getAttributes());

$csattr['client.title']='clientTitle';

$csattr['Project.title']='projectTitle';



Try using together() method to resolve your "ambiguous" problem

http://www.yiiframework.com/doc/guide/database.arr#performing-relational-query

Did not work :(