Yii Framework Forum: CDbCommand error - Unknown column - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

CDbCommand error - Unknown column

#1 User is offline   paullorentzen 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 20-October 10

Posted 09 December 2010 - 09:10 AM

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()
{
$usersArray = CHtml::listData($this->users, 'id', 'username');
return $usersArray;
}


I have no idea how to begin troubleshooting this.

Can anyone help me?
0

#2 User is offline   Thirumalai 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 58
  • Joined: 20-November 10

Posted 09 December 2010 - 09:17 AM

View Postpaullorentzen, on 09 December 2010 - 09:10 AM, said:

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()
{
$usersArray = CHtml::listData($this->users, 'id', 'username');
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'));

0

#3 User is offline   jefftulsa 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 168
  • Joined: 06-October 08
  • Location:Austin, TX

Posted 09 December 2010 - 09:47 AM

View Postpaullorentzen, on 09 December 2010 - 09:10 AM, said:

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()
{
$usersArray = CHtml::listData($this->users, 'id', 'username');
return $usersArray;
}


I have no idea how to begin troubleshooting this.

Can anyone help me?


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

#4 User is offline   paullorentzen 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 20-October 10

Posted 09 December 2010 - 09:51 AM

View PostThirumalai, on 09 December 2010 - 09:17 AM, said:

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'));



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');
$options = $project->userOptions;
// $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',
);
}
0

#5 User is offline   paullorentzen 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 20-October 10

Posted 09 December 2010 - 10:31 AM

View Postjefftulsa, on 09 December 2010 - 09:47 AM, said:

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


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))'),
0

#6 User is offline   jrewing 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 09-December 10

Posted 09 December 2010 - 04:55 PM

I have the exact same problem.
0

#7 User is offline   jrewing 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 09-December 10

Posted 09 December 2010 - 05:25 PM

View Postjrewing, on 09 December 2010 - 04:55 PM, said:

I have the exact same problem.

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

#8 User is offline   paullorentzen 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 20-October 10

Posted 09 December 2010 - 07:26 PM

View Postjrewing, on 09 December 2010 - 05:25 PM, said:

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


What did you change to solve the problem?
0

#9 User is offline   paullorentzen 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 20-October 10

Posted 09 December 2010 - 07:33 PM

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.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users