[FLOW3-general] One question about mm relation

Regine Rosewich regine.rosewich at hoellenberg.biz
Fri Feb 22 16:43:40 CET 2013


Hi Manfred,

your problem might be the missing persistence instructions in your
many-to-many parameter like

* @ORM\ManyToMany\(inversedBy="...", cascade={"persist"}) 

<<or "...cascade={"persist", "remove"}" or "...cascade={"all"}">>

Thus you tell the persistence manager how to handle an object which is
added, updated or removed.

Btw: I'm developing a large business-web-application with TYPO3/FLOW and
ExtJS4 which unfortunately needs several one-to-many associations. First I
did it as you do by @ORM\ManyToMany... which worked technically but did
cause, under others,  performance problems with large datasets. In the end I
decided to solve my problems with manually defined join classes (in your
case this would be a class "CompanyActions") and join the dependent classes
with OneToMany joins to that class. Beside the performance impact, this way
has the advantage that you are free to add additional properties to the join
class which conceptually do not belong to one of the dependent classes (like
for example a default action for a certain company)

Regine  

> -----Ursprüngliche Nachricht-----
> Von: flow3-general-bounces at lists.typo3.org [mailto:flow3-general-
> bounces at lists.typo3.org] Im Auftrag von Manfred Rutschmann - VOLUMEN
> Werbe-/Internetagentur
> Gesendet: Freitag, 22. Februar 2013 14:07
> An: flow3-general at lists.typo3.org
> Betreff: [FLOW3-general] One question about mm relation
> 
> 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
> _______________________________________________
> FLOW3-general mailing list
> FLOW3-general at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/flow3-general




More information about the FLOW3-general mailing list