I made a beforeSave method in my model (extends GXActiveRecord), the if isNewRecord never gets triggered. My beforeSave() gets called, though.
When I print the $this->isNewRecord variable, it's false. When is this variable set to false anyway? I'm very sure it's new
public function beforeSave(){
if(parent::beforeSave())
{
if($this->isNewRecord){
$this->setAttribute('doc_status','new');
print "something";
}else{
$this->setAttribute('doc_status','updated');
}
return true;
} else { return false;
}
CActiveRecord->isNewRecord is false if you've never saved it before.
E.g.
$model = new Product;
$model->name = uniqid("bar");
echo "isNewRecord?".$model->isNewRecord; // 1 (true)
$model->save();
echo "isNewRecord?".$model->isNewRecord; // (false)
$model = Product::model();
$model->name = uniqid("foo");
echo "isNewRecord?".$model->isNewRecord; // (false)
$model->save();
echo "isNewRecord?".$model->isNewRecord; // (false)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With