Problem after update to 1.0.5

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?

Quote

_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?

Did you call parent::__construct()?

Quote

Did you call parent::__construct()?

Yes, I've called it in __construct of my BaseDocumentModel. But the I get an:

Fatal error: Maximum function nesting level of '100' reached, aborting!..

Could you please show your complete __construct() code, including both BaseDocumentModel and TeaserDocument?

Quote

Could you please show your complete __construct() code, including both BaseDocumentModel and TeaserDocument?

Do I have to call parent::__construct() in my TeaserDocument too?

If you override it, yes.

Quote

If you override it, yes.

Currently I have only a __construct method in my BaseDocumentModel class which looks like this:

  public function __construct()

  {

    $this->strBaseModel = str_replace('Document', '', $this->tableName());

    parent::__construct();

  }

and my TeaserDocument doesn't have a __construct method.

If you PM me your code I will figure it out.

Are you sure it validates?

you have:

$objDocument->save(true);

'true' is the default argument, did you mean to have it false?

When you override __construct(), you should keep its original signature.



public function __construct($attributes=array(),$scenario='')


{


    parent::__construct($attributes,$scenario);


    // your own code


}


Hello,

What is the method in 1.0.5 to initialize related objects in AR?

In 1.0.4 I had "$parent->rel = new RelModel;"

Now the __set method doesn't give access to that property.

Paul

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).

Thank you,

I'll try that.

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