Many To Many Tablas Anidada

hola comunidad en yii ¿¿ soy nuevo esto pero tengo una duda tengos dos una tabla producto y tabla orden ya hice las relaciones y me carga los datos pero en Cgridview de el admin.php orden producto necesito que me salga asi

es decir que los nombre de los producto sea una columnas mas de cgridview

id producto id orden nombre_Producoto1 nombre_Producto2 ----> header cabecera

001         001      CantidadProducto1 CantidadProducto2 

otro ejemplo

id producto id orden Cocacola Pepsi

001           001       100        50

Tabla producto {

id_Producto

Nombre_Producto

Cantidad_Producto

}

tabla orden_producto

{

Id_Producto

id_orden

o

}

Tabla orden {

id_orden

Nombre_Producto

Cantidad_Producto

}

CODIGO DEL MODELO ORDEN_pRODUCTO

 */


class OrdenP extends CActiveRecord


{





        public $CantidadOrden;


        public $Nombre_Producto;


        public $Cantidad_Producto;


        public $Hora_Final;


        public $Hora_Inicio;





    /**


         * @return string the associated database table name


         */


        public function tableName()


        {


                return 'orden_p';


        }





        /**


         * @return array validation rules for model attributes.


         */


        public function rules()


        {


                // NOTE: you should only define rules for those attributes that


                // will receive user inputs.


                return array(


                        array('id_orden, id_producto', 'required'),


                        array('id_orden, id_producto', 'numerical', 'integerOnly'=>true),


                        // The following rule is used by search().


                        // @todo Please remove those attributes that should not be searched.


                        array('id, id_orden, id_producto', 'safe', 'on'=>'search'),


                );


        }





        /**


         * @return array relational rules.


         */


        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(


                        'idOrden' => array(self::BELONGS_TO, 'Orden', 'id_orden'),


                        'idProducto' => array(self::BELONGS_TO, 'Producto', 'id_producto'),


                );


        }





        /**


         * @return array customized attribute labels (name=>label)


         */


        public function attributeLabels()


        {


                return array(


                        'id' => 'ID',


                        'id_orden' => 'Id Orden',


                        'id_producto' => 'Id Producto',


                );


        }





        /**


         * Retrieves a list of models based on the current search/filter conditions.


         *


         * Typical usecase:


         * - Initialize the model fields with values from filter form.


         * - Execute this method to get CActiveDataProvider instance which will filter


         * models according to data in model fields.


         * - Pass data provider to CGridView, CListView or any similar widget.


         *


         * @return CActiveDataProvider the data provider that can return the models


         * based on the search/filter conditions.


         */











        public function search()


        {


                // @todo Please modify the following code to remove attributes that should not be searched.





                $criteria=new CDbCriteria;





                $criteria->compare('id',$this->id);


                $criteria->compare('id_orden',$this->id_orden);


                $criteria->compare('id_producto',$this->id_producto);


                $criteria->with = array('idOrden', 'idProducto'); 


                $criteria->compare('idProducto.NombreProducto',$this->Nombre_Producto,true);


                $criteria->compare('idorden.Hora_Inicio',$this->Hora_Inicio,true);


                $criteria->compare('idorden.Hora_Final',$this->Hora_Final,true);


                $criteria->compare('idOrden.Cantidad_litro', $this->CantidadOrden,true);


                $criteria->compare('idProducto.Cantidad_Producto',$this->Cantidad_Producto,true);








                return new CActiveDataProvider($this, array(


                        'criteria'=>$criteria,


                ));





     


        }


  public static function getProducto ()


     {


         


         return CHtml::ListData(Producto::model()->FindAll(),'Codigo_Producto','Nombre_Producto');


     }





        /**


         * Returns the static model of the specified AR class.


         * Please note that you should have this exact method in all your CActiveRecord descendants!


         * @param string $className active record class name.


         * @return OrdenP the static model class


         */


        public static function model($className=__CLASS__)


        {


                return parent::model($className);


        }


}

VIEW DE ORDEN prODUCTO

<?php

/* @var $this OrdenPController */

/* @var $model OrdenP */

$this->breadcrumbs=array(

'Orden Ps'=&gt;array('index'),


'Manage',

);

$this->menu=array(

array('label'=&gt;'List OrdenP', 'url'=&gt;array('index')),


array('label'=&gt;'Create OrdenP', 'url'=&gt;array('create')),

);

Yii::app()->clientScript->registerScript(‘search’, "

$(’.search-button’).click(function(){

&#036;('.search-form').toggle();


return false;

});

$(’.search-form form’).submit(function(){

&#036;('#orden-p-grid').yiiGridView('update', {


	data: &#036;(this).serialize()


});


return false;

});

");

?>

<h1>Manage Orden Ps</h1>

<p>

You may optionally enter a comparison operator (<b>&lt;</b>, <b>&lt;=</b>, <b>&gt;</b>, <b>&gt;=</b>, <b>&lt;&gt;</b>

or <b>=</b>) at the beginning of each of your search values to specify how the comparison should be done.

</p>

<?php echo CHtml::link(‘Advanced Search’,’#’,array(‘class’=>‘search-button’)); ?>

<div class="search-form" style="display:none">

<?php $this->renderPartial(’_search’,array(

'model'=&gt;&#036;model,

)); ?>

</div><!-- search-form -->

'id'=&gt;'orden-p-grid',

<?php $this->widget(‘zii.widgets.grid.CGridView’, array(

'dataProvider'=&gt;&#036;model-&gt;search(),


'filter'=&gt;&#036;model,








'columns'=&gt;array(


	


	'id_orden',


	'id_producto',


       


      array(


                            'name'=&gt; 'Nombre_Producto',


                  'value'=&gt;'&#036;data-&gt;idProducto-&gt;Nombre_Producto',


              


                 ),  


           


            


                     array(


                             'name'=&gt;'CantidadOrden',


                  'value'=&gt;'&#036;data-&gt;idOrden-&gt;Cantidad_litro',


              


                 ),  


                          array(


                 'name'=&gt;'Cantidad_Producto',


                  'value'=&gt;'&#036;data-&gt;idProducto-&gt;Cantidad_Producto',


              


                 ),       


        array 


        (


             'name'=&gt;'Hora_Inicio',


                  'value'=&gt;'&#036;data-&gt;idOrden-&gt;Hora_Inicio',


            


            


        ),


               array 


        (


             'name'=&gt;'Hora_Final',


                  'value'=&gt;'&#036;data-&gt;idOrden-&gt;Hora_Final',


            


            


        ),


        array(

‘name’=>‘Nombre_Producto’,

‘value’=>’$data->idProducto->Nombre_Producto’, //Con esto se mostrará la descripción de la categoría en vez del id_categoria

‘filter’=> OrdenP::getProducto(), //Esto ya es un agregado, muestra un combobox con todas las categorias para poder filtrarlas, si no lo ponemos usa el id_categoria por defecto

//Debemos de crear una función estática en el modelo Categorias que se llame getListCategorias(), esto es totalmente opcional

),

	array(


		'class'=&gt;'CButtonColumn',


	),


),

)); ?>

Que manía tenéis de no poner las cuotes de código!!!!!!

Es q paso de leer todo el tocho que has puesto sin formatear. Si no te he entendido mal deseas mostar un campo del modelo A en el modelo B no siendo la clave de la relación.

En tu CGridview en la vista "admin" tendrás algo como esto:




...

'columns'=>array(

                 'idproducto',

                 'idorden',

                 'nombreproducto'

...



Y tu lo que quieres es mostrar el nombre de la orden,no?

Entonces sustituyes :




'idorden'



por




array(  

      'header'=>'Nombre Orden', 

      'value'=>'$data->nombreRelacion->nombreorden' 

     )



Y listo. La variable "oculta" llamada "$data" tiene los datos recogidos para rellenar el CGridview.

Un saludo.