Automatic Insert In Detale Table

I have 2 table:

1- user:

  • id

  • username

  • password

2- profile



[*]user_id=>referenced to user->id

[*]some access rules



in User class I have

public function relations()


		return array(

			'profile' => array(self::HAS_ONE, 'Profile', 'user_id'),



and in Profile class:

public function relations()


	return array(

		'user' => array(self::BELONGS_TO, 'User', 'user_id'),



I want when created new user, in profile table created one record with user_id reference.

so I do this:(in User class)

protected function afterSave()



		$this->profile = new Profile;

		$this->profile->user_id = $this->id;



Code run widthout any exception, but dont insert anything in profile table!

whats wrong?

There may be a problem with Profile rules, check rules method,

by the way I think it’s better to use $profile instead of $this->profile

why not use a transaction in user create action function ?