Wizard Behavior On Related Model Submition

i have user and profile table

profile table is related from user table by user_id

my question is how can i get user id to be populated on my profile user_id when the wizard is Finished below is my code…

i only have error on my user_id

public function wizardFinished($event) {

                if ($event->step===true){

                        //save data to database


            $user = new User();

            $profile = new Profile();

            $user->username = $event->data['user']['username'];

            $user->password = $event->data['user']['password'];

            $user->email = $event->data['user']['email'];

            [b]$profile->user_id = $event->data['profile']['user_id'];[/b] //how can i get the id from user table

            $profile->lname = $event->data['profile']['lname'];

            $profile->fname = $event->data['profile']['fname'];

                        if($user->save() && $profile->save()){

                                $this->render('completed', compact('event'));





                        $this->render('finished', compact('event'));




the data is not saved to database at that point key is no generated, you have to call $user->save() before you access the user_id