can't retrieve related ar object record from newly inserted ar object

is this a bug?

i use it in afterSave() to implement a common fuction:

public function afterSave()

{

    $this->post->replyQty += 1;

    $this->post->save();

}

it raise a exception says that $this->post is null

What is $this->post? Is it loaded before you call its save()?

Beware pf going into endless loops, Yuest.  You are putting a save in afterSave(), which in turn calls another afterSave(). !

<?php

class Reply extends CActiveRecord

{

    //…

    public function relations()

    {

        return array(

            'author'=>array(self::BELONGS_TO, 'User', 'userId'),

            'post'=>array(self::BELONGS_TO, 'Post', 'postId'),

        );

    }

    //…

    /*

    protected function afterSave()

    {

        $this->post->replyQuantity += 1;

        $this->post->lastReplyTime = date("Y-m-d H:i:s");

        $this->post->save();

    }

    * this doesn't works, i must use the code below: */

    protected function afterSave()

    {

        $post = Topic::model()->findbyPk($this->postId);

        $post->replyQuantity += 1;

        $post->lastReplyTime = date("Y-m-d H:i:s");

        $post->save();

    }

    protected function afterDelete()

    {

        $this->post->replyQuantity -= 1;

        $this->post->save();

    }//this works when deleting

}

Thanks. This is fixed in SVN.