The Value For The Column "idauthdata" Is Not Supplied When Querying The Table "authdata".

Hello everybody!

I’am trying to do an authorization in my Yii application.

In my database I have the authData table which contains 2 primary key:


  `idauthData` int(11) NOT NULL AUTO_INCREMENT,

  `login` varchar(45) NOT NULL,

  `password` varchar(80) NOT NULL,

  `role` varchar(45) NOT NULL,

  `email` varchar(60) NOT NULL,

  `employee_idEmployee` int(11) NOT NULL,

  PRIMARY KEY (`idauthData`,`employee_idEmployee`),

  UNIQUE KEY `idauthData_UNIQUE` (`idauthData`),

  KEY `fk_authData_employee1_idx` (`employee_idEmployee`)


In my Authdata model I override the primaryKey() method:

public function primaryKey() 


	return array('idauthData', 'employee_idEmployee');


But when I trying to find a row in Authdata activeRecord class using findByPk() method I`am getting an exception:

private function getModel(){

      if (!$this->isGuest && $this->_model === null){

          $this->_model = Authdata::model()->findByPk(array($this->id), array('select' => 'role'));


      return $this->_model;


The exception has next description:

The value for the column "idauthData" is not supplied when querying the table "authdata".

C:\xampp\htdocs\helloworld\protected\components\WebUser.php(14): CActiveRecord->findByPk(array("15"), array("select" => "role"))

09 }

10 }


12 private function getModel(){

13 if (!$this->isGuest && $this->_model === null){

14 $this->_model = Authdata::model()->findByPk(array($this->id), array(‘select’ => ‘role’));

15 }

16 return $this->_model;

17 }

18 }

19 ?>

And I don`t know how to resolve this problem.

I know that this is a simple mistake and I just miss some moment. That why if somebody could help me I will be very glad!

Thanks in advance


This is the way you can pass two primary key …not with two different array :)

[color=#000000]$model [/color][color=#666600]=[/color][color=#000000] [/color][color=#660066]TranslationMessage[/color][color=#666600]::[/color][color=#000000]model[/color]color=#666600->[/color][color=#000000]findByPk[/color][color=#666600]([/color][color=#000000]array[/color][color=#666600]([/color][color=#008800]‘id’[/color][color=#000000] [/color][color=#666600]=>[/color][color=#000000] $id[/color][color=#666600],[/color][color=#000000] [/color][color=#008800]‘language’[/color][color=#000000] [/color][color=#666600]=>[/color][color=#000000] $language[/color][color=#666600]));[/color]


I hope this will help you

Problem solved =)

Thanks a lot for help.

The problem was occurred because I didn`t pass the second primary key employee_idEmployee to findByPk() method.

The right variant of code should look like this:

private function getModel(){

        if (!$this->isGuest && $this->_model === null){

            $this->_model = Authdata::model()->findByPk(array(

            	'idauthData' => $this->id, 

            	'employee_idEmployee' => 'employee_idEmployee'), array('select' => 'role'));


        return $this->_model;