Doctrine - 只需一次 save() 即可插入多行
如何在 Doctrine 中调用一次 save()
方法将多行插入表中?
How do I insert multiple rows into table calling save()
method once in Doctrine?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
将每条记录添加到
Doctrine_Collection
对集合对象调用save()
。仅当所有记录都针对同一个表时,这才有效。否则你就不走运了。
Add each record to a
Doctrine_Collection
the callsave()
on the collection object.This only works if all the records are for the same table. Otherwise you're out of luck.
这是另一个解决方案,在 Dotrine 1.2 上进行了测试。
无需保存每条记录,flush()会自动找出所有未保存的实例并将其全部保存。
Here another solution ,tested on Doctrine 1.2.
No need to save each records, the flush() automatically finds out all the unsaved instances and saves them all.
如果你使用 symfony2 那就很简单了
If you use symfony2 it is so easy
1)声明所有表。
2)创建表格。
3)发送到多个表。
4)保存数据。
1)声明所有表。
2)创建表单
3)插入到多个表中。
4)持久化数据
1)Declare all the tables.
2)Create the form.
3)Send to multiple tables.
4)Persist data.
1)Declare all the tables.
2)Create form
3)Insert into multiple tables.
4)Persist data
我查看了 Doctrine (1.2.x)“Collection.php”的“save”方法的代码,我看到的只是这样:
如何使用一个 mysql INSERT 插入所有记录?
I took a look into the code of the "save" method of the Doctrine (1.2.x) "Collection.php" and all I saw is something like this:
How should this ever insert all records with one mysql INSERT?