[SOLVED]Query Builder,CActiveRecord

I got two records at my products table, these two products fall on the same category

I built this sql query to get all the stuff in the same category




SELECT * FROM category_products

LEFT JOIN wswebpb ON category_products.ProductID = wswebpb.ProductID 

LEFT JOIN category ON category_products.catid = category.catid;



and I have this in one of my controllers to test if it’ll work




	public function actionIndex()

	{

                $items = Yii::app()->db->createCommand()

                        ->select('*')

                        ->from('category_products cp')

                        ->leftjoin('wswebproducts pb','category_products.ProductID AND wswebproducts.ProductID')

                        ->leftjoin('category cat','category_products.:cid AND category.:cid')

                        ->where(array(':cid'=>$this->loadModel($id)->ProductID))

                        ->queryRow();

                

                $dataProvider = new CActiveDataProvider('Wswebproducts',

                        array('criteria'=> $items));

		$this->render('index',array(

                    'dataProvider' => $dataProvider,

                ));



that code above produces

"product not found"




        public function loadModel($id)

        {

            $model = Wswebproducts::model()->findByPk((int)$id);

            if($model === null)

                throw new CHttpException(404,'Product not found');

            return $model;

        }



I don’t really know what to do, any help is appreciated much

thanks in advance :)

What is $id? From your code I don’t quite understand where it takes its value. May be it is null and that’s why you get your error?

problem solved, nevermind this thread, I drop all those crap i posted, I added an additional column at the products table instead, then hard coded the catid at the cmenu, makes life easier ;D