在我的實體中,documents我有一個名為的字段linkedDocuments:class Documents { /** * @ORM\ManyToMany(targetEntity="App\Entity\Documents") * @ORM\JoinTable(name="documents_documents", * joinColumns={@JoinColumn(name="link_origin", referencedColumnName="id")}, * inverseJoinColumns={@JoinColumn(name="link_destination", referencedColumnName="id")} * ) * @Groups("documents") */ private $linkedDocuments; public function __construct() { $this->linkedDocuments = new ArrayCollection(); }在我的控制器中,我創(chuàng)建了一個對象:$table = $this->em->getRepository(Documents::class)->findAll();這是輸出:array:1 [▼ 0 => Documents^ {#6414 ▼ -id: 1 -linkedDocuments: PersistentCollection^ {#5724 ▼ -snapshot: [] -owner: Documents^ {#6414} -association: array:19 [ …19] -em: EntityManager^ {#2786 …11} -backRefFieldName: null -typeClass: ClassMetadata {#2613 …} -isDirty: false #collection: ArrayCollection^ {#2820 ▼ -elements: [] } #initialized: true } }]我的數(shù)組集合是空的。但我希望它有兩個元素,因為我在 mySQL 數(shù)據(jù)庫中看到了它們。像這樣: -elements: array:2 [▼ 0 => linkedDocuments^ {#1204 ?} 1 => linkedDocuments ?} ]
如何使用連接表和多對多關(guān)系顯示 ArrayCollection 的元素?
ibeautiful
2022-01-02 14:42:31