Yii Framework Forum: How to create relation or attribute base on relations - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

How to create relation or attribute base on relations Rate Topic: -----

#1 User is offline   Wesely Chong 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 19-June 12

Posted 19 June 2012 - 05:36 AM

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.
0

#2 User is offline   3One 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 25
  • Joined: 19-January 12
  • Location:Switzerland

Posted 19 June 2012 - 10:36 AM

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
0

#3 User is offline   Wesely Chong 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 19-June 12

Posted 19 June 2012 - 08:54 PM

View Post3One, on 19 June 2012 - 10:36 AM, said:

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?
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users