How to create relation or attribute base on relations

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(

			'charges' => array(self::HAS_MANY, 'Charge', 'ShopLot_LotNo'),

			'payments' => array(self::HAS_MANY, 'Payment', 'ShopLot_LotNo'),

			'owner' => array(self::BELONGS_TO, 'Owner', 'Owner_OwnerID'),

			'shopFloor' => array(self::BELONGS_TO, 'Shopfloor', 'LotFloor'),

			'DueDebit' => array(self::STAT, 'Charge', 'ShopLot_LotNo','select'=> 'SUM(Amount)', 'condition'=>'ChargeDueDate>"now()"'),

			'Debit' => array(self::STAT, 'Charge', 'ShopLot_LotNo','select'=> 'SUM(Amount)'),

			'Credit' => array(self::STAT, 'Payment', 'ShopLot_LotNo','select'=> 'SUM(Amount)'),





I want to add an attribute ‘Balance’ base on ‘Credit-Debit’, How I can do this?

Thanks for help.

do you meant to get balance you need credit and debit? there is the parameter through, maybe this is what

you are looking for, this works like this:

Model Profile:

‘ContactDetails’ => array(self::HAS_ONE,‘ContactDetails’,array(‘cd_id’=>‘cd_id’),‘through’=>‘Profile’),

‘City’ => array(self::HAS_ONE,‘City’,array(‘zip_code’=>‘zip_code’),‘through’=>‘ContactDetails’)

Profile has an Contact details which is linked with the address_id on the profile

the city is linked with the zip_code on the contact details

Thanks for help.

But what I need is I need to get balance. The formula is I have 2 tables ‘Charge’ and ‘Payment’. I need to get balance = payments - charges

I create model profile:

‘Debit’ => array(self::STAT, ‘Charge’, ‘ShopLot_LotNo’,‘select’=> ‘SUM(Amount)’),

‘Credit’ => array(self::STAT, ‘Payment’, ‘ShopLot_LotNo’,‘select’=> ‘SUM(Amount)’),

It work. but I need a Balance in Model profile.

Maybe It can be

'Balance' => array(self::STAT, 'Payment, Charge', 'ShopLot_LotNo','select'=> 'SUM(Payment.Amount) -SUM(Charge.Amount'),

It work?