Work Around For Composite Primary Key If Using Scope?

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?

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.