Relational Query as DataProvider for Grid View

Dear Yii-developers,

I have a problem regarding a relational query from which I want to show the results in a Grid View. I’ve set up my relations in the corresponding model, so it’s easy to access the corresponding results. The problem is that I don’t know and can not find any examples how to display this in a Grid View, because the relational query does not return a DataProvider.

My system consist of an Order, who has a has many relation with Colbert and Pantalon. I use the following easy to use code to get an array of Colbert objects:


Bu how do I transform this into a DataProvider, I also tried it by creating a DataProvider in the controller, with the following code:

        $dataProviderColberts=new CActiveDataProvider('Order', array(

            'criteria' => array(

                'with' => 'colberts', // relational query name



Bu that displays all Colbert, not only specific to this Order. The fields the Order and Colbert are linked on are and colbert.orderId!

I’ve already searched for examples and looked through the manual, but I can’t find the solution! I’m sorry if this is an easy answer but you would really help me out!

Thanks in advance!

Hi, maybe you can use a CArrayDataProvider and use the colberts realation as the rawData parameter, I haven’t tried something like that but it might help.

you have to use expression in cgred












Hi everybody, I have the same question. Is there any way to convert array returned by the relation to CActiveDataProvider? It would be very useful for displaying dependent CGirdView-s in a view of the main object. Of course I could use CArrayDataProvider but it’s much less flexible and functional.

There is a ‘dinamic’ dataprovider (misspelling intentional) extension. May want to try that.

Thanks, this extension is useful enough for me, it’s just what I was looking for, but I had to make small code change to make it support MANY_MANY type of relations. See my comment here: