Cascading objects save action


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


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)







		return $comment->save();



post controller



	 * Displays a particular model.


	public function actionView()











	 * 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()->user->setFlash('commentSubmitted','Thank you for your comment. Your comment will be posted once it is approved.');




		return $comment;


Or just use tabular methods.

Thanks dude, its clear to me now.