find by foreign key

Hi everyone how can I substitute the findByPk in loadModelb because $id is not Pk and it is a Fk. thanks




	public function loadModel($id)

	{

		$model=Useraccounts::model()->findByPk($id);

		if($model===null)

			throw new CHttpException(404,'The requested page does not exist.');

		return $model;

	}

	public function loadModelb($id)

	{

		$modelb=Basicdetails::model()->findByPk($id);

		if($modelb==null)

			throw new CHttpException(404,'The requested page does not exist.');

		return $modelb;

	}




I solved it thanks…




$modelb=Basicdetails::model()->findByAttributes(array('userid'=>$id,));



Hi ,

These Solution that May Help.

public function loadModel($id)

    {


            $criteria=New CDbCritieria;


 	$critieria->condition='<where Condition>'; //Remove these if not required.


	$model=Useraccounts::model()->findByAttributes(array('<fieldname>'=>$id),$criteria);





            if($model===null)


                    throw new CHttpException(404,'The requested page does not exist.');


            return $model;


    }


    public function loadModelb($id)


    {


            $criteria=New CDbCritieria;


 	$critieria->condition='<where Condition>'; //Remove these if not required.


	$model=Useraccounts::model()->findByAttributes(array('<fieldname>'=>$id),$criteria);


            if($modelb==null)


                    throw new CHttpException(404,'The requested page does not exist.');


            return $modelb;


    }