我有一个简单的实体:
<?php
namespace SomeBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection as ArrayCollection;
/**
* @ORM\Entity(repositoryClass="SomeBundle\Entity\Repository\PostRepository")
* @ORM\Table(name="Posts")
*/
class Post {
/**
* @ORM\Id()
* @ORM\Column(name="ID", type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $ID;
/**
* @ORM\Column(name="Title", type="string", length=255, nullable=true)
*/
protected $Title;
/**
* @ORM\Column(name="Text", type="text", nullable=true)
*/
protected $Text;
/**
* @ORM\Column(name="Picture", type="string", length=100, nullable=true)
*/
protected $Picture;
public function __toString() {
return $this->Title;
}
public function getID() {
return $this->ID;
}
public function getTitle() {
return $this->Title;
}
public function setTitle($title) {
$this->Title = $title;
return $this;
}
public function getText() {
return $this->Text;
}
public function setText($text) {
$this->Text = $text;
return $this;
}
public function getPicture() {
return $this->Picture;
}
public function setPicture($picture) {
$this->Picture= $picture;
return $this;
}
}
我有一个控制器动作:
public function editAction($ID, Request $request) {
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository("SomeBundle:Post")->find($ID);
if (!$entity)
throw $this->createNotFoundException("Unable to find post.");
$form = $this->createEditForm($entity);
$form->handleRequest($request);
$this->validateData($form, $entity);
if ($form->isValid()) {
$entity->setTitle('Title');
$entity->setPicture('somefilepath');
$em->flush();
}
...
}
因此,当我触发editAction函数时,Title字段会正确更新,但不会更新Picture。在分析器的更新查询中甚至没有列出图片字段:
UPDATE Posts SET Title = ? WHERE ID = ?
答案 0 :(得分:0)
问题已解决。实体的自定义存储库似乎没有将Picture字段附加到实体,因此在刷新期间,doctrine没有处理该字段。