Cascading objects save action

Hi,

I came from java and used to use Hibernate ORM to persist data.

To save a book with several pages I would do this:

Book book = new Book();

//set book properties

List pages;

//set all the pages in the list

book.setPages(pages);

bookDao.save(book);

With some cascade properties this save action would save the book and all the pages with their respective relationship.

There’s some way to do something similar in Yii. Or should I save all objects separatelly.

hi, this is like post and comments, in blog demo is some example

post Model




.............


        /**

     * Adds a new comment to this post.

     * This method will set status and post_id of the comment accordingly.

     * @param Comment the comment to be added

     * @return boolean whether the comment is saved successfully

     */

	public function addComment($comment)

	{

		if(Yii::app()->params['commentNeedApproval'])

			$comment->status=Comment::STATUS_PENDING;

		else

			$comment->status=Comment::STATUS_APPROVED;

		$comment->post_id=$this->id;

		return $comment->save();

	}

..........



post controller




.................


	/**

	 * Displays a particular model.

	 */

	public function actionView()

	{

		$post=$this->loadModel();

		$comment=$this->newComment($post);


		$this->render('view',array(

			'model'=>$post,

			'comment'=>$comment,

		));

	}

.................


        /**

	 * Creates a new comment.

	 * This method attempts to create a new comment based on the user input.

	 * If the comment is successfully created, the browser will be redirected

	 * to show the created comment.

	 * @param Post the post that the new comment belongs to

	 * @return Comment the comment instance

	 */

	protected function newComment($post)

	{

		$comment=new Comment;

		if(isset($_POST['ajax']) && $_POST['ajax']==='comment-form')

		{

			echo CActiveForm::validate($comment);

			Yii::app()->end();

		}

		if(isset($_POST['Comment']))

		{

			$comment->attributes=$_POST['Comment'];

			if($post->addComment($comment))

			{

				if($comment->status==Comment::STATUS_PENDING)

					Yii::app()->user->setFlash('commentSubmitted','Thank you for your comment. Your comment will be posted once it is approved.');

				$this->refresh();

			}

		}

		return $comment;

	}



Or just use tabular methods.

http://www.yiiframework.com/doc/guide/1.1/en/form.table

Thanks dude, its clear to me now.