I have an object inside my model (CActiveRecord), I have to initialize this object with a property from the database. To do that I use the init() method but the property is null
here the code
class CompanyFidelityCard extends CActiveRecord
public function init()
$this->privacy_code is null coz if I change it for this
I have tried as well with afterConstruct() method by the result is the same.
any help? thanks in advance
PD; sorry if I have done a mistake is my first post, I have read the guidline and search about this here…
PPD;sorry for my english too
Hi Adria, welcome to the forum.
Well, it seems to me that you are trying to use CActiveRecord in a very strange way. CActiveRecord is not designed to be used like that. You should not call a heavy method from init().
For instance, if you call CompanyFidelityCard::model()->findAll(), then init() will be called as many times as there are rows in company_fidelity_card table.
You should consider making use of relational active record functionality instead.
I agree with softark
First of all, is attribute privacy_code initialized ?
If initializes from database then use the afterFind