在我的实体中,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();
}
在我的控制器中,我创建了一个对象:
$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
}
}
]
我的数组集合是空的。但我希望它有两个元素,因为我在 mySQL 数据库中看到了它们。像这样:
-elements: array:2 [▼
0 => linkedDocuments^ {#1204 ▶}
1 => linkedDocuments ▶}
]
ibeautiful
HUH函数
随时随地看视频慕课网APP