doctrine2 - How can I add a related entity to a user object at the point of creation in FOSUserBundle? -


in symfony2 rc3, trying create related entity on user object (fosuserbundle) @ point of user creation can display appropriate fields on edit profile form. doing following in registrationformhandler.

class registrationformhandler { protected $request; protected $usermanager; protected $form;

public function __construct(form $form, request $request, usermanagerinterface $usermanager) {     $this->form = $form;     $this->request = $request;     $this->usermanager = $usermanager; }  public function process($confirmation = null) {     $user = $this->usermanager->createuser();     $this->form->setdata($user);      if ('post' == $this->request->getmethod()) {         $this->form->bindrequest($this->request);          if ($this->form->isvalid()) {             if (true === $confirmation) {                 $user->setenabled(false);             } else if (false === $confirmation) {                 $user->setconfirmationtoken(null);                 $user->setenabled(true);             }             $prog = new \mybundle\corebundle\entity\programme();              $prog->setstartdate(date_create());             $prog->setenddate(date_create());             $prog->setweeklytarget(4);             $prog->setgoal('');              $user->addprogrammes($prog);             $this->usermanager->updateuser($user);              return true;         }     }      return false; } 

}

the programme record created in database null user_id seems association isn't working correctly. know might causing this?

the solution $programmes->setuser($this); in addprogrammes method of user entity


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -