2017-07-18 1 views
0

J'ai une relation ManyToMany beetween « Lot » et « BailProprietaire »ManyToMany ne fonctionne pas dans l'auditeur avec la propriété virtuelle

Quand je reçois une entité « BailProprietaire », je vois les entités « lot » liées Mais quand je reçois une entité "Lot", je ne vois pas des entités "BailProprietaire" liée

En lot.orm.yml, j'ai:

AppBundle\Entity\Lot: 
type: entity 
repositoryClass: AppBundle\Repository\LotRepository 
table: lot 
.... 
.... 
manyToMany: 
    bauxProprietaire: 
     targetEntity: BailProprietaire 
     mappedBy: lots 

En bailProprietaire.orm.yml, j'ai:

AppBundle\Entity\BailProprietaire: 
type: entity 
table: bail_proprietaire 
repositoryClass: AppBundle\Repository\BailProprietaireRepository 
.... 
.... 
manyToMany: 
    lots: 
     targetEntity: Lot 
     inversedBy: bauxProprietaire 
     fetch: LAZY 
     joinTable: 
      name: bail_proprietaire_lots 
      joinColumns: 
       bail_id: 
        referencedColumnName: id 
      inverseJoinColumns: 
       lot_id: 
        referencedColumnName: id 
lifecycleCallbacks: { } 

voyez-vous quelque chose qui me manque?

grâce

EDIT: Ajouter php entité Code

Lot.php

class Lot 
{ 
    /** 
    * @var integer 
    */ 
    private $id; 



    /** 
    * @var \Doctrine\Common\Collections\Collection 
    */ 
    private $bauxProprietaire; 


    /** 
    * Constructor 
    */ 
    public function __construct() 
    { 
     $this->bauxProprietaire = new ArrayCollection(); 
    } 


    /** 
    * Get id 
    * 
    * @return integer 
    */ 
    public function getId() 
    { 
     return $this->id; 
    } 





    /** 
    * Add bauxProprietaire 
    * 
    * @param \AppBundle\Entity\BailProprietaire $bauxProprietaire 
    * 
    * @return Lot 
    */ 
    public function addBauxProprietaire(\AppBundle\Entity\BailProprietaire $bauxProprietaire) 
    { 
     $this->bauxProprietaire[] = $bauxProprietaire; 

     return $this; 
    } 

    /** 
    * Remove bauxProprietaire 
    * 
    * @param \AppBundle\Entity\BailProprietaire $bauxProprietaire 
    */ 
    public function removeBauxProprietaire(\AppBundle\Entity\BailProprietaire $bauxProprietaire) 
    { 
     $this->bauxProprietaire->removeElement($bauxProprietaire); 
    } 

    /** 
    * Get bauxProprietaire 
    * 
    * @return \Doctrine\Common\Collections\Collection 
    */ 
    public function getBauxProprietaire() 
    { 
     return $this->bauxProprietaire; 
    } 


} 

BailProprietaire.php

class BailProprietaire 
{ 


    /** 
    * @var integer 
    */ 
    private $id; 


    /** 
    * @var \Doctrine\Common\Collections\Collection 
    */ 
    private $lots; 

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

    /** 
    * Get id 
    * 
    * @return integer 
    */ 
    public function getId() 
    { 
     return $this->id; 
    } 



    /** 
    * Add lot 
    * 
    * @param \AppBundle\Entity\Lot $lot 
    * 
    * @return BailProprietaire 
    */ 
    public function addLot(\AppBundle\Entity\Lot $lot) 
    { 
     $this->lots[] = $lot; 

     return $this; 
    } 

    /** 
    * Remove lot 
    * 
    * @param \AppBundle\Entity\Lot $lot 
    */ 
    public function removeLot(\AppBundle\Entity\Lot $lot) 
    { 
     $this->lots->removeElement($lot); 
    } 

    /** 
    * Get lots 
    * 
    * @return \Doctrine\Common\Collections\Collection 
    */ 
    public function getLots() 
    { 
     return $this->lots; 
    } 

} 

EDIT 2: en fait, cela fonctionne, mais pas avec l'auditeur

en fait je vois les entités "BailPropriétaire" quand je reçois un "lot" mais quand je vide les données, j'ai un auditeur. Dans cet auditeur, j'appelle une propriétée virtuelle de "Lot.php" où j'ai:

if (!empty($this->bauxProprietaire)) { 
     .... 
    } else { 
     .... 
    } 

mais $ this-> bauxProprietaire est toujours vide

+0

Pouvez-vous nous montrer votre code d'entité PHP? –

Répondre

0

Ok, je l'ai trouvé le problème.

Quand je fais $ this-> bauxProprietaire, j'ai une "Doctrine \ ORM \ PersistentCollection" mais quand je regarde la collection dans cet objet, il y a 0 élément enter image description here

mais si je fais $ this- > bauxProprietaire-> toArray(), je vois ma relation

Je ne comprends pas pourquoi, mais cela fonctionne