Include attributes from antother model

Hi All,

I have two models that are related(customer and commissions).

In my customer model i have a virtual attribute ‘fullname’




class Customer extends CActiveRecord

{

.....

	public function getFullName(){

		return $this->first_name . ' ' . $this->last_name;

	}

.....

}



My question is: Is it possible to use Customer’s fullname attribute in Commissons to create another virtual attribute?

I’ve tried the following but i get an error ‘Trying to get property of non-object




class Commissions extends CActiveRecord

{

.....

	public function getCustomerName(){

		return $this->customer->fullname;

	}

.....

}



Let me know

Thanks

Oliver




	public function getCustomerName(){

		return $this->customer instanceof Customer ? $this->customer->fullname : null;

	}



@Phtamas Thanks for the reply!! i tried your suggestion in my commissions model and i got the following error "Property "Commissions.fullname" is not defined."

This is what i have in my view file:




		array(

			'name'=>'fullname',

			'header'=>'Customer',

		),



Any Ideas?

Thanks again!

Oliver

Following the wiki article Understanding Virtual Attributes and get/set methods should solve your problem ;)

Thanks Kokomo! I was able to figure it out. Phtamas Suggestion did work, i had to change the attribute name in my view file.

Thanks million guys!!

Oliver