CDbCommand :: Column 'name' in order clause is ambiguous

Hello!

I'm trying to out put my data  in a table datagrid using sort options.

The table:

User

name

login

password

Profile_id

Profile

name

label

User model relations

	public function relations()


	{


        return array(


		'profile'=>array(self::BELONGS_TO, 'Profile', 'Profile_id',


						'select'=>'Profile.name,Profile.label'),


        'log'=>array(self::HAS_MANY,'Log','User_id')


        );


	}

Profile model relations

	public function relations()


	{


		return array(


 			'user'=>array(self::HAS_MANY, 'User', 'Profile_id')


		);


	}

I want my admin user datagrid table to show Profile.name ASC as DefaultOrder.

At first moment, it works when I use :

		$sort=new CSort('User');


		$sort->defaultOrder = 'label asc';


		$sort->applyOrder($criteria);


		


		$pages=new CPagination(User::model()->with('profile')->count($criteria));


		$pages->pageSize=self::PAGE_SIZE;


		$pages->applyLimit($criteria);


		


		$userList=User::model()->with('profile')->findAll($criteria);

But When I click at 'name' th link to sort as name, I got it:

CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'name' in order clause is ambiguous

My query LOG:

    SELECT COUNT(DISTINCT `User`.`id`) FROM `User`  LEFT OUTER JOIN `Profile` t1 ON `User`.`Profile_id`=t1.`id`


		


SELECT `User`.`id` AS t0_c0, `User`.`name` AS t0_c1, `User`.`login` AS t0_c2, `User`.`password` AS t0_c3, `User`.`active` AS t0_c4, `User`.`deletedDate` AS t0_c5, `User`.`Profile_id` AS t0_c6, t1.`name` AS t1_c1, t1.`label` AS t1_c2, t1.`id` AS t1_c0 FROM `User`  LEFT OUTER JOIN `Profile` t1 ON `User`.`Profile_id`=t1.`id` ORDER BY `name` LIMIT 10


		    

check this: http://www.yiiframew…opic,540.0.html

It was enought to solve my problem. Thnks!

  • Why didnt it had showed up when I looked for?