原则不会更新实体的字段


Doctrine doesn't update entity's field

我有一个简单的实体:

<?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();
    }
    ...
}

因此,当我触发编辑操作功能时,标题字段已正确更新,但图片未正确更新。图片字段甚至没有在探查器的更新查询中列出:

UPDATE Posts SET Title = ? WHERE ID = ?

此问题已修复。实体的自定义存储库似乎没有将图片字段附加到实体,因此 doctrine 在刷新期间不会处理该字段。