Relation Between Models And Display In Cgridview

table 1


loader


bl_no PK

bl_cbm

bl_value

table 2


cargo


awb_no

bl_no

awb_cbm

awb_value


1 loader = has many cargo



Objective:

= get the sum of cargo.awb_cbm and cargo.awb_value

= after that, display the following in cgridview




-------------------------------------------------

| bl_no | bl_value | sum(cargo.awb_value) | Net |

-------------------------------------------

| DD142 | 5000     | 3000                 | 200 |

-------------------------------------------------



same thing in CBM, get the diffrence of the loader.bl_cbm and cargo.awb_cbm

i use this query and im success to get all i need


SELECT a.*,

        (SELECT SUM(b.cbm) as ccbm FROM cargo b

    	   WHERE b.bl_no = a.bl_no

        ) as cbm_difference,

        (SELECT SUM(b.awb_value) as selling FROM cargo b

    	WHERE b.bl_no = a.bl_no) NET

FROM loader a


my problem is:

i dont now how to make a function that can query and display in cgridview, i dont know if this is right?

my relation model


Model : loader

[color="#FF8C00"]


public function relations()

	{

		


		return array(

                          "x" => array(self::HAS_MANY, "cargo", "bl_no",),

		);

                

	}

[/color]


please anyone can help T_T… im tired to find out

thanks in advance, sorry for my english low…

Reinhard Navarro

First of all CGridView uses DataProviders, so you can put your SQL code into a CSQLDataProvider object and the use it (filter, etc)

On the other hand you cannot create relations to SQL code.

If you need to calculate some children fields you might need CActiveRecord::STAT queries/relations.

Hope this helps.

Allowed memory size of 8388608 bytes exhausted (tried to allocate 14592 bytes) in /var/www/html/monitoring/protected/extensions/bootstrap/widgets/TbBaseMenu.php on line 149

i goty another problem help please