How To Create Cgridview With Three Models


I am having trouble trying to build a CGridView table in Yii with three models. Here is the scenario:

Table: Products

prod_id, prod_name

HAS_MANY -> Prices

Table: Regions

reg_id, reg_name

HAS_MANY -> Prices

Table: Prices

price_id, prod_id, reg_id, price

BELONGS_TO -> Products

BELONGS_TO -> Prices

Products/Regions | Region#1 | Region#2 | ... | Region#N


Product#1        | Price#1  | Price#2  | ... | Price#N

Product#2        | Price#1  | Price#2  | ... | Price#N

Product#3        | Price#1  | Price#2  | ... | Price#N


Product#N        | Price#1  | Price#2  | ... | Price#N

I have all the relations and ActiveRecords set up for this. I know I can create this GridView in a non Yii way. But i want to know if there is a way to do this with CGridView because i need to have filters, pagination and sorting in this situation.




check this wiki that referred το multiple same models

you have to modify some code to union the fields

This is a good idea but how am i really supposed to approach my problem using this. Lets say, I am starting from Prices because the prices have access to both stores and products. Lets say we know that usually the number regions are way less than the number of products. So as an example, I have 20 products and 5 regions. Am i going to have 5 activedataproviders (1 per region)? How efficient is it relative to plain SQL. I know activerecord is usually slower than plain sql query but in my scenario it sounds like an overhead, isnt it? Im going to give it a shot and do couple tests to see how it is.



try something like that:

$this->widget('zii.widgets.grid.CGridView', array(







               'value'=> '$data->Regions[0]->Prices->price')



               'value'=> '$data->Regions[1]->Prices->price')