Symfony 许多未在具有虚拟属性的侦听器中工作

Symfony 许多未在具有虚拟属性的侦听器中工作,symfony,doctrine-orm,many-to-many,Symfony,Doctrine Orm,Many To Many,“Lot”和“BailProprietaire”之间有很多关系 当我得到一个实体“BailProprietaire”时,我看到实体“lot”链接在一起 但当我得到一个实体“Lot”时,我看不到实体“BailProprietaire”链接 在lot.orm.yml中,我有: AppBundle\Entity\Lot: type: entity repositoryClass: AppBundle\Repository\LotRepository table: lot .... .... manyT

“Lot”和“BailProprietaire”之间有很多关系

当我得到一个实体“BailProprietaire”时,我看到实体“lot”链接在一起 但当我得到一个实体“Lot”时,我看不到实体“BailProprietaire”链接

在lot.orm.yml中,我有:

AppBundle\Entity\Lot:
type: entity
repositoryClass: AppBundle\Repository\LotRepository
table: lot
....
....
manyToMany:
    bauxProprietaire:
        targetEntity: BailProprietaire
        mappedBy: lots
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: {  }
在bailProprietaire.orm.yml,我有:

AppBundle\Entity\Lot:
type: entity
repositoryClass: AppBundle\Repository\LotRepository
table: lot
....
....
manyToMany:
    bauxProprietaire:
        targetEntity: BailProprietaire
        mappedBy: lots
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: {  }
你看到我错过的东西了吗

谢谢

编辑:添加php实体代码

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;
    }

}
编辑2:事实上,它对监听器有效,但对监听器无效

事实上,当我得到“很多”时,我看到实体“BailProprietaire”,但当我刷新数据时,我有一个监听器。在这个侦听器中,我调用了一个虚拟属性“Lot.php”,其中我有:

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

但是$this->bauxProprietaire总是空的

好的,我发现了问题

当我执行$this->bauxProprietaire时,我有一个“条令\ORM\PersistentCollection”,但当我在这个对象中查看集合时,有0个元素

但是如果我做$this->bauxProprietaire->toArray(),我就会看到我的关系


我不明白为什么,但它能工作

你能给我们看看你的PHP实体代码吗?