Add Attribute In Activerecord

I’m trying to add an extra attribute in my model, but without success.

Added to the model attribute:


...

public $extraAttr;

...

and safe in rules


...

array('extraAttr', 'safe'),

...

Even so, this attribute does not appear in:


$model->attributes

I can only access it by:


$model->extraAttr

But I need to access it by aattributes the model. How do?

Thank you!

You can’t. Check out the attributeNames() method’s source code in the API docs. It returns only attributes read from the table schema from the database. This method is used in setAttributes, getAttributes and others.

I have a solution: http://www.yiiframework.com/forum/index.php/topic/46108-adicionar-attribute-no-activerecord/