[FLOW3-general] One question about mm relation
Manfred Rutschmann - VOLUMEN Werbe-/Internetagentur
rutschmann at agentur-volumen.de
Fri Feb 22 14:07:27 CET 2013
Hi guys,
one question about mm relation. I have two objects:
Company
Action
Many Companys can have many Actions.
I need access to the acions from the company context. But i need the access from Actions to the company to. Now i have the objects defnied as follow:
Company:
/**
* The action
* @ORM\ManyToMany(inversedBy="company")
* @var \Doctrine\Common\Collections\Collection<\Kunden\Domain\Model\Action>
*/
protected $action;
Action:
/**
* The company
* @ORM\ManyToMany(mappedBy="action")
* @var \Doctrine\Common\Collections\Collection<\Kunden\Domain\Model\Company>
*/
protected $company;
This configuration gives me the following table: kunden_domain_model_company_action_join
Now i create in my ActionController a new action. For this case i have only one company to assign:
/**
* createAction
* @param \Kunden\Domain\Model\Action $action
* @param \Kunden\Domain\Model\Company $company
* @return void
*
*/
public function createAction(\Kunden\Domain\Model\Action $action, \Kunden\Domain\Model\Company $company){
$collection = new \Doctrine\Common\Collections\ArrayCollection;
$collection->add($company);
$aktion->setCompany($collection);
$this->aktionRepository->add($action);
$this->redirect("edit", "Company", NULL, array("company" => $company));
}
In this case no relation is created by flow3. To create a mm relation between two objects i have to do the following:
/**
* createAction
* @param \Kunden\Domain\Model\Action $action
* @param \Kunden\Domain\Model\Company $company
* @return void
*
*/
public function createAction(\Kunden\Domain\Model\Action $action, \Kunden\Domain\Model\Company $company){
$collection = new \Doctrine\Common\Collections\ArrayCollection;
$collection->add($action);
$company->setAction($collection);
$this->aktionRepository->add($action);
$this->companyRepository->update($company);
$this->redirect("edit", "Company", NULL, array("company" => $company));
}
Ist that right? I have update the company with the action as collection by hand?
Many thanks for assistance!
Regards Manfred Rutschmann
More information about the FLOW3-general
mailing list