[FLOW3-general] One question about mm relation

Manfred Rutschmann - VOLUMEN Werbe-/Internetagentur rutschmann at agentur-volumen.de
Fri Feb 22 18:54:48 CET 2013


Hi Regine,

many thanks for your assistance. I have tried all the things you say, but nothing work. By Example:

Company: My Main object

	/**
	 * The aktion
	 * @ORM\ManyToMany(inversedBy="company", cascade={"persist"})
	 * @var \Doctrine\Common\Collections\Collection<\Kunden\Domain\Model\Aktion>
	 */
	protected $aktion;


	public function __construct() {
		$this->aktion = new \Doctrine\Common\Collections\ArrayCollection();
	}


	/**
	 * Set the aktion
	 *
	 * @param \Doctrine\Common\Collections\Collection<\Kunden\Domain\Model\Aktion> $aktion
	 * @return void
	 */
	public function setAktion(\Doctrine\Common\Collections\Collection $aktion) {
		$this->aktion = $aktion;
	}

	
	/**
	 * Adds the given aktion.
	 *
	 * @param \Kunden\Domain\Model\Aktion $aktion
	 * @return void
	 */
	public function addAktion(\Kunden\Domain\Model\Aktion $aktion) {
		$this->aktion->add($aktion);
	}

	/**
	 * Removes the given aktion
	 *
	 * @param \Kunden\Domain\Model\Aktion $aktion 
	 * @return void
	 */
	public function removeAktion(\Kunden\Domain\Model\Aktion $aktion) {
		$this->aktion->removeElement($aktion);
	}

	/**
	 * Returns all known aktionen
	 *
	 * @return \Doctrine\Common\Collections\Collection<\Kunden\Domain\Model\Aktion>
	 */
	public function getAktion() {
		return clone $this->aktion;
	}	




Now my aktion object:



	/**
	 * The company
	 * @ORM\ManyToMany(mappedBy="aktion", cascade={"persist"})
	 * @var \Doctrine\Common\Collections\Collection<\Kunden\Domain\Model\Company>
	 */
	protected $company;	


	/**
	 * Constructs this Aktion
	 *
	 */
	public function __construct() {
		$this->company = new \Doctrine\Common\Collections\ArrayCollection();
	}



	/**
	 * Set the company
	 *
	 * @param \Doctrine\Common\Collections\Collection<\Kunden\Domain\Model\company> $company
	 * @return void
	 */
	public function setCompany(\Doctrine\Common\Collections\Collection $company) {
		$this->company = $company;
	}

	
	/**
	 * Adds the given company.
	 *
	 * @param \Kunden\Domain\Model\Company $company
	 * @return void
	 */
	public function addCompany(\Kunden\Domain\Model\Company $company) {
		$this->company->add($company);
	}

	/**
	 * Removes the given company
	 *
	 * @param \Kunden\Domain\Model\Company $company 
	 * @return void
	 */
	public function removeCompany(\Kunden\Domain\Model\Company $company) {
		$this->company->removeElement($company);
	}

	/**
	 * Returns all known company 
	 *
	 * @return \Doctrine\Common\Collections\Collection<\Kunden\Domain\Model\company>
	 */
	public function getCompany() {
		return clone $this->company;
	}



in my AktionController i do this:

	/**
	 * createAction
	 * @param \Kunden\Domain\Model\Aktion $aktion
	 * @param \Kunden\Domain\Model\Company $company
	 * @return void
	 * 
	 */
	public function createAction(\Kunden\Domain\Model\Aktion $aktion, \Kunden\Domain\Model\Company $company){
		$aktion->addCompany($company);
		$this->aktionRepository->add($aktion);
		$this->redirect("edit", "Company", NULL, array("company" => $company));
	}	



The create action gets two arguments, the new aktion and a related company. in this case only one company (many companies comes in a other controller). Then i add the company argument to the aktion. And for my understand must flow3 create a relation in kunden_domain_model_company_aktion_join for added company in the aktion. But all annotations for cascade, jointable or targetEntity in the aktion model are succesfull ignored...

Then in tried some other options:

targetEntity="\Kunden\Domain\Model\Company"
JoinTable="kunden_domain_model_aktion_join"

Nothing.

I have no idea whats going wrong. doctrine:update brings no expection, the aktion is persisted, but the relation from this point is never created...?!

Thanks for your time!

Regards Manfred



Am 22.02.2013 um 16:43 schrieb Regine Rosewich <regine.rosewich at hoellenberg.biz>:

> 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
> 
> 
> _______________________________________________
> 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