doufang1954 2016-08-03 17:51
浏览 55
已采纳

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

I have a problem with a PersistentCollection.

I have an Object User (herited of FOSUserbundle user class) who have an EmdebedDocument Seance. The Seance have an Array of Event. My Seance Class:

/**
* @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;

And my class Event

/**
* @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;

I give the event from user with:

$user->getSeance()->getDispos()

This function returns a empty PersistentCollection while they are events in database.

When dump the return of getDispos() method I have: dump of result getDispos() method

I dont't understant why I have mongoData field with my data but arrayCollection empty.

Thank you for yout help.

  • 写回答

1条回答 默认 最新

  • douao2019 2016-08-05 08:43
    关注

    PersistentCollection is initialized lazily - for performance reasons, the data from database is held in mongoData. The collection is initialized during the first time you need some data from it (or try to modify it) - then the data held in mongoData is hydrated into your embedded documents and that is added to decorated coll. All this is happening transparently to you, just try using your collection instead of dumping it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog