npCoda
(Sh Humble)
November 30, 2010, 10:52am
1
I am beginner in Yii framework. I was practicing through ebbok" Aggile WebDevelopment with Yii 1.1 ". I got following error in code when I clicked to Create Issue.
CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column ‘users.tbl_project_user_assignment(project_id’ in ‘where clause’
E:\xampp\htdocs\trackstar\protected\models\Project.php(113)
00101:
00102: return new CActiveDataProvider(get_class($this), array(
00103: ‘criteria’=>$criteria,
00104: ));
00105: }
00106:
00107: /**
00108: * populate users
00109: */
00110: public function getUserOption()
00111: {
00112: $userArray = array();
[size=“3”]00113: $userArray = CHtml::listData($this->users,‘id’,‘username’); [/size]
00114: return $userArray;
00115:
00116: /*return array(
00117: self::USER_1=>‘User1’,
00118: self::USER_2=>‘User2’,
00119: );*/
00120: }
00121: }
Can anybody help me ?
jefftulsa
(Jefftulsa)
November 30, 2010, 5:22pm
2
Can you provide the details of what your table looks like? Was your table created using the following sql?:
[sql]CREATE TABLE tbl_project_user_assignment
(
project_id
Int(11) NOT NULL,
user_id
Int(11) NOT NULL,
create_time
DATETIME,
create_user_id
INTEGER,
update_time
DATETIME,
update_user_id
INTEGER,
PRIMARY KEY (project_id
,user_id
)
) ENGINE = InnoDB
;[/sql]
I had this error as well. It turns out I was doing:
‘users’ => array(self::HAS_MANY , ‘User’, ‘tbl_project_user_assignment(project_id, user_id)’),
…instead of:
‘users’ => array(self::MANY_MANY , ‘User’, ‘tbl_project_user_assignment(project_id, user_id)’),
in the Project model’s relations array.
npCoda
(Sh Humble)
December 2, 2010, 4:03am
5
ddumitrescu:
I had this error as well. It turns out I was doing:
‘users’ => array(self::HAS_MANY , ‘User’, ‘tbl_project_user_assignment(project_id, user_id)’),
…instead of:
‘users’ => array(self::MANY_MANY , ‘User’, ‘tbl_project_user_assignment(project_id, user_id)’),
in the Project model’s relations array.
I am using the following relations:
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
‘issue’=>array(self::HAS_MANY, ‘Issue’,‘project_id’),
‘users’=>array(self::HAS_MANY,‘user’,‘tbl_project_user_assignment(project_id,user_id)’),
);
}
Yeah, that’s how I had it too when I got the error. Try changing the ‘users’ one to MANY_MANY. It fixed it for me.
npCoda
(Sh Humble)
December 2, 2010, 6:09am
7
Yes you are right. There should be MANY_MANY relationship, as there is third table provided with FK so it must be MANY_MANY. Later I realize.
Thanks for you support too.