重用 Doctrine_Record 对象来保存模型的多个实例
我正在 Symfony 应用程序中开发某种通知模块。我正在迭代用户的Doctrine_Collection
,为每个在其个人资料中具有活动标志的用户创建一个通知
:
// Create and define common values of notification
$notification = new Notification();
$notification->setField1('...');
$notification->setField2('...');
...
// Post notification to users
foreach ( sfGuardUserTable::getInstance()->findByNotifyNewOrder(true) as $user ) {
$notification->setUserId($user->getId());
$notification->save();
}
问题是,一旦我保存了第一个通知,我就无法重用该对象以在数据库中存储新记录。我已尝试使用 null
和 ''
来 $notification->setId()
,但保存会更新对象而不是保存新对象。
有没有办法重用 $notification
对象?我想这样做,因为通知字段创建的逻辑有点复杂。
I am working on some kind of notifications module in a Symfony application. I am iterating over a Doctrine_Collection
of users to create a Notification
for every user that has a flag active in its profile:
// Create and define common values of notification
$notification = new Notification();
$notification->setField1('...');
$notification->setField2('...');
...
// Post notification to users
foreach ( sfGuardUserTable::getInstance()->findByNotifyNewOrder(true) as $user ) {
$notification->setUserId($user->getId());
$notification->save();
}
Problem is that once I have saved the first notification I cannot reuse the object to store new records in the database. I have tried $notification->setId()
with null
and ''
, but saving updates the object instead of saving a new.
Is there a way to reuse the $notification
object? I would like to do that because logic of notification fields creation is a bit complex.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
复制是什么你正在寻找。
Copy is what you're looking for.