Quick parent and child model save

It’s not actualy problem. more like i’m curious if its possible to save to related tables/models automatically. Like this:




$post = new Post();

$post->content = 'New post content';

$post->comment->text = 'New comment that belongs to new post';

$post->Save();



instead of




$post = new Post();

$post->content = 'New post content';

if($post->Save()) {

   //success

   $comment = new Comment();

   $comment->post_id = app()->db->getLastInsertID();

   $comment->text = 'New comment that belongs to new post';

   $comment->save();

}



No not possible yet :(

Hi,

I have same question for above. Any new development of Yii supporting above implementation?

Thanks…

Nope. But depending on what you want to achieve, overriding your model’s afterSave() method might do. It isn’t quick but at least it’s convenient.