Magento 数据库事务
在 Magento 中,如何在单个事务中将数据插入到多个表中,并在过程中出现任何错误时回滚。?我可以编写自定义查询并使用事务,但我更喜欢使用 Magento 方法来完成。
IN Magento How can I insert data in multiple tables in a single transaction and rollback if there is any error in the process.?? I can write custom queries and use transactions but I would prefer if I can do it using Magento methods.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您尝试做的是模型保存,则接受的答案很好。这将使您可以将任何数字与回滚链接在一起。
但是,如果您正在执行可能触发回滚或自行回滚的其他操作,那么您需要使用更底层的操作:
您还可以从模型获取连接,但可能没有可用的连接。
The accepted answer is fine if what you are attempting to do is model saves. This will let you chain any number together with rollback.
If, however, you are performing other actions that might trigger roll-back or are rolling back themselves, then you want to use something more low-level:
You can also get the connection from a model, but there may not be one available.
您可以尝试 Mage::getModel('core/resource_transaction')。相关文档位于此处。
但可能更有用,这里有一个 示例 使用它从订单创建发票。
You can try Mage::getModel('core/resource_transaction'). The documentation for it such as it is here.
But probably more useful, here is an example of using it to create an invoice from an order.