duanji2014 2018-04-20 00:41
浏览 32
已采纳

我可以多次在Doctrine中保留相同的文档吗?

Can I create a new Document Object and then keep persisting over and over with the document manager in Doctrine within the same linear list of instructions?

I am implementing a logging system within my Symfony2 Project with Doctrine, Stripe and MongoDB. Basically I want to keep logging progress as each instruction is executed. The reason for this is because sometimes the instructions can only reach a certain point because the Bank will decline the card and an exception will be thrown. There are no 100% definite errors. And I want to be able to pick up where I left off.

For instance.

$charge = new StripeChargeCardObject(); //this is the Document
$charge->setEvent("card.charger");
$charge->setPhase(1);
$this->dm = new DocumentManager();
$dm->persist($charge);
$dm->flush();

$payload = new StripePayload($event);

$charge->setPhase(2);
$charge->setPayload($payload);
$this->dm->persist($charge);
$this->dm->flush();

.....

As I keep going down the list, changing the values of the Document until there is an Exception thrown.

Can I use the same $charge Document, keep editing it, and keep persisting it? Or do I need to load it again each and every time after I persist and flush?

  • 写回答

1条回答 默认 最新

  • drwj4061 2018-04-20 04:26
    关注

    As long as you don't flush, nothing is saved in your DB, so you can still edit your object and persist.

    In your actual code you create a new object each time the instructions are read. I am not sure this is the behavior you want.

    If you want to have a single object in DB, you should fetch the object you want to edit (and create a new one only if your query returns null result).

    Hope it will help you to see what's better for you !

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

报告相同问题?

悬赏问题

  • ¥15 计算二重积分∫∫e^(x+y)dxdy,其中0≤x≤1,0≤y≤1,试分别用复合辛普森公式(取n=4)以及高斯求积公式(取n=4)计算积分 给出matlab程序
  • ¥15 opencv 无法读取视频
  • ¥15 用matlab 实现通信仿真
  • ¥15 按键修改电子时钟,C51单片机
  • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))
  • ¥20 5037端口被adb自己占了
  • ¥15 python:excel数据写入多个对应word文档
  • ¥60 全一数分解素因子和素数循环节位数
  • ¥15 ffmpeg如何安装到虚拟环境
  • ¥188 寻找能做王者评分提取的