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';


instead of

$post = new Post();

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

if($post->Save()) {


   $comment = new Comment();

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

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



No not possible yet :(


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


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.