php - Doctrine2 One to One Relation parent id not saved in child -
i have problem relation saving. have users , profiles. not users have profiles decided profiles owner of relationships. when create user. have user form , profile form. have
$user = new entity\user(); $profile = new entity\profile(); $user->setprofile($profile);
i user object have
/** * @orm\onetoone(targetentity="my\infobundle\entity\profile",cascade={"persist", "remove"}, mappedby="user") */ protected $profile;
in profile have
/** * @orm\onetoone(targetentity="my\userbundle\entity\user", inversedby="profile") * @orm\joincolumn(name="user_id", referencedcolumnname="id") */ protected $user;
so when save it, user_id not save in profile table. , have not relation betwean user , profile. can fix this? or should chnage owning in relationships.
class user { public function setprofile(profile $profile) { $this->profile = $profile; $profile->setuser($this); } }
edit : onetoone relationship mustn't use mappedby
, inversedby
.
Comments
Post a Comment