将一个实体合并到另一个实体中


Merging an entity inside an other entity

我正在使用一个名为"Session"的实体,该实体保存在HTTP会话中。此会话与一篇文章有关,该文章与一幅图像有关。问题是当我想通过更改一个简单的日期时间行来更新这个会话时。我想在每次调用AJaX请求时更新它。当文章的图片不为空时,我在刷新时出错,不知怎么的,我的图片变成了空。我不知道该怎么处理。当文章中没有图像时,一切都正常。而且,不知怎么的,当我在一个完全随机的函数中调用"flush"时,我得到了一个错误,即我的实体无效("在执行';INSERT INTO photo..时发生了异常")。

这是我用来阅读和更新会话的代码。

$em = $this->getDoctrine()->getManager();
$currentSession = $symfonySession->get('currentSession');
if($currentSession == null)
    return new Response(404);
$currentSession = $em->merge($currentSession);
$currentSession->setUpdated(new 'Datetime());
$em->flush();
$em->detach($currentSession);
$symfonySession->set('currentSession', $currentSession);

嗯,我仍然不知道它到底是如何工作的,但我只删除了cascade={"all"}