2018-04-20 00:41
浏览 32


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
$this->dm = new DocumentManager();

$payload = new StripePayload($event);



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?

图片转代码服务由CSDN问答提供 功能建议

我可以创建一个新的文档对象,然后在Doctrine中的文档管理器中保持一遍又一遍地保持相同的线性 说明清单?

我正在使用Doctrine,Stripe和MongoDB在我的Symfony2项目中实现日志记录系统。 基本上我希望在执行每条指令时保持记录进度。 这样做的原因是因为有时指令只能到达某一点,因为银行会拒绝该卡,并且会抛出异常。 没有100%明确的错误。 而且我希望能够从我离开的地方继续前行。


  $ charge = new StripeChargeCardObject();  //这是Document 
 $ charge-> setEvent(“card.charger”); 
 $ charge-> setPhase(1); 
 $ this-> dm = new DocumentManager(); 
  $ dm-> persist($ charge); 
 $ dm-> flush(); 
 $ payload = new StripePayload($ event); 
 $ charge-> setPhase(2);  
 $的电荷> setPayload($有效载荷); 
 $的这 - > DM->坚持($电荷); 
 $的这 - > DM->冲洗(); 
。  .... 


我可以使用相同的$ charge文档,继续编辑它,并保持持久性吗? 或者在我坚持和冲洗后每次都需要再次加载它?

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

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 !

    解决 无用
    打赏 举报

相关推荐 更多相似问题