ntomsheck
(Ntomsheck)
August 13, 2013, 8:02pm
1
Good Afternoon!
I have a table which has a composite primary key (id, data_year), and I set up a default scope to always search one specific data_year. Since half the primary key is already accounted for, why do I still get a 400 error when I’m trying to pull a record up by ID?
What is the error message? How do you "pull" the record?
ntomsheck
(Ntomsheck)
August 15, 2013, 6:11am
3
Hi,
Sorry for the delay.
My issue was that I was relying on the giix created methods too heavily. Before, I had this:
public function actionView($id) {
$this->render('view', array(
'model' => $this->loadModel($id, 'Student'),
));
}
But I have since rewritten it to this:
public function actionView($id) {
$model = new Student();
$model->id = $id;
$this->render('view', array(
'model' => $model->find(),
));
}
which is working. Thanks for responding!
You should use a static instance for calling find, like this:
public function actionView($id) {
$this->render('view', array(
'model' => Student::model()->findByPk($id),
));
}
findByPk() should work fine with composite primary keys.