PersistentCollection 未初始化,但数据库中的数据使用 Symfony 和 Doctrine

One*_*ill 1 php doctrine mongodb symfony

我有一个 PersistentCollection 的问题。

我有一个对象用户(从 FOSUserbundle 用户类继承),他有一个 EmdebedDocument Seance。降神会有一系列事件。我的降神课:

/**
* @MongoDB\EmbeddedDocument
*/
class Seance
{
/**
 * @MongoDB\Id
 */
protected $id;

/**
 * @MongoDB\EmbedMany(targetDocument="Event")
 */
protected $dispos ;

/**
 * @MongoDB\Field(type="string")
 */
protected $rayonDeplacement;

/**
 * @MongoDB\Field(type="string")
 */
protected $lieu;

/**
 * @MongoDB\Field(type="string")
 */
protected $prix;

/**
 * @MongoDB\Field(type="string")
 */
protected $nbPersonne;
Run Code Online (Sandbox Code Playgroud)

还有我的班级活动

/**
* @MongoDB\EmbeddedDocument
*/
class Event extends BaseEvent
{
/**
 * @var integer
 * @MongoDB\Id
 */
protected $id;

/**
 * @var \DateTime
 * @MongoDB\Field(type="date")
 * @Assert\NotNull()
 */
protected $startDate;
/**
 * @var \DateTime
 * @MongoDB\Field(type="date")
 * @Assert\NotNull()
 */
protected $endDate;
Run Code Online (Sandbox Code Playgroud)

我给用户的事件:

$user->getSeance()->getDispos()
Run Code Online (Sandbox Code Playgroud)

当它们是数据库中的事件时,此函数返回一个空的 PersistentCollection。

当转储 getDispos() 方法的返回时,我有: 结果转储 getDispos() 方法

我不明白为什么我的数据有 mongoData 字段但 arrayCollection 为空。

谢谢你的帮助。

mal*_*rzm 5

PersistentCollection延迟初始化 - 出于性能原因,数据库中的数据保存在mongoData. 该集合在您第一次需要它的一些数据(或尝试修改它)时被初始化 - 然后保存的数据mongoData被水合到您的嵌入文档中,并被添加到装饰的coll. 所有这一切对您来说都是透明的,只需尝试使用您的收藏而不是倾倒它。