CDbCommand error - Unknown column

I am learning Yii framework via the "Agile Web Application Development … " book and am getting this error during testing:

  1. ProjectTest::testGetUserOptions

CDbException: CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column ‘users_users.user_id)’ in ‘on clause’

The column name is "users_users.user_id" and I think it should be just "users.user_id".

The error was generated when executing this command:

public function getUserOptions()


	[b]$usersArray = CHtml::listData($this->users, 'id', 'username');[/b]

	return $usersArray;


I have no idea how to begin troubleshooting this.

Can anyone help me?

if u want to list out from ur model User follow this code hope it will help u

return(CHtml::listData(User::model()->findAll(), 'id', 'username'));

Could you share what your relations() method looks like in your Project model class?

Thanks for the reply.

I’m not sure where to use your line of code.

My error is generated when running the unit test below and is triggered by the bold line

	public function testGetUserOptions()


		$project = $this->projects('project1');

		[b]$options = $project->userOption[/b]s;

		// $this->assertTrue(is_array($options));

		// $this->assertTrue(count($options) > 0);


I just created the get method in the Project AR that looks like this:

public function getUserOptions()


	$usersArray = CHtml::listData($this->users, 'id', 'username');

	return $usersArray;


If I manually return an array from the Project AR (using this code), everything works fine:

public function getUserOptions()


	return array(

		'test1' => 'test1',

		'test2' => 'test2',



Here are my Project AR relations

‘issues’ => array(self::HAS_MANY, ‘Issues’, ‘project_id’),

‘users’ => array(self::MANY_MANY, ‘User’, ‘tbl_project_user_assignment(project_id, user_id))’),

I have the exact same problem.

It works! Hurray. Double check everything is my suggestion.

What did you change to solve the problem?

jrewing is right! Check EVERYTHING!

If you look at the users element relations() method of the model class, there is an extra left paren. toward the end.

Thanks for everyones help; I’ll look at little close at the simple things next time.