After an update to the current version of Yii, I've got the following code not working:
$booSave = $booSave && $objDocument->save(true);
$strDocument = $objDocument->id.'-'.$strDocument;
"$booSave" contains true, but nothing gets saved into database. Everything works fine with Yii 10.0.4.
Any ideas???
EDIT:
I've looked into the model, and found out, that there is [CActiveRecord:_new] => false. Seems to be a bug, becuase I've tested it with the following lines of code:
$objTeaserDocument = new TeaserDocument();
CVarDumper::dump($objTeaserDocument,100,true);
which shows the following output:
TeaserDocument#1
(
[CActiveRecord:_md] => null
[CActiveRecord:_new] => false
[CActiveRecord:_attributes] => array()
[CActiveRecord:_related] => array()
[CActiveRecord:_c] => null
[CModel:_errors] => array()
[CModel:_va] => null
[CModel:_se] => ''
[CComponent:_e] => null
[CComponent:_m] => null
)
EDIT2:
find out something more. The problem seems to when the _construct() method is called.
_new is set by setIsNewRecord which is called in __construct().
What is the class name of your AR?
I have a BaseDocumentModel and TeaserDocument extends BaseDocumentModel. Does it mean, that I have to set $this->setIsNewRecord in __construct() of BaseModelDocument?
You may call $parent->addRelatedRecord($name,$model). However, you should try not doing this because the related model can be retrieved automatically (via lazy loading).
In the previous example "$parent" is a new object. "rel" is not set (I can't access it as property). Maybe works, but as I told you I don't have any access to the related as properties.
In what you told me looks like I don't now to get that relation (first) and at the end to set it. isset($parent->rel) is false.
Paul
EDIT: it's a general problem (possibly in my code, I'll check more) accessing the related models. Even hasRelated returns false if $parent is a new object
EDIT 2: for a new parent getRelated('rel') returns null (as previous versions), but __set doesn't give access to related objects as properties. addRelatedRecord works (but with 3 params) as a replacement