Doctrine ObjectSelect 上引用实体的错误数据类型

Wrong datatype for referenced entity on Doctrine ObjectSelect

我有一个使用 Doctrine 的 ObjectSelect 制作下拉列表的表单

$this->add(array(
        'name' => 'category',
        'type' => 'DoctrineModule\Form\Element\ObjectSelect',
        'options' => array(
            'label' => 'Category',
            'object_manager' => $em,
            'target_class' => 'Blog\Entity\Category',
            'property' => 'name'
        ),
        'attributes' => array(
            'required' => true
        )
 ));

我遇到的问题是,这应该引用另一个实体的 ID,但是它一直在抛出 "Expected value of type "Blog\Entity\Category" 对于关联字段 "Blog\Entity\Post#$category",改为 "string"。"

这是表格中的 var_dump,重要的部分

object(Zend\InputFilter\InputFilter)[337]
  protected 'factory' => null
  protected 'data' => 
    array (size=5)
      'id' => string '' (length=0)
      'title' => string 'asdasd' (length=6)
      'content' => string '<p>asdasd</p>' (length=13)
      'category' => string '3' (length=1)
      'submit' => string 'Add' (length=3)

和我的 addAction

public function addAction()
{   
    $form = new PostForm($this->getEntityManager());
    $form->setHydrator(new DoctrineEntity($this->getEntityManager(),'Blog\Entity\Post'));

    $form->get('submit')->setValue('Add');

    $request = $this->getRequest();
    if ($request->isPost()) {
        $post = new Post();
        $form->setInputFilter($post->getInputFilter());
        $form->setData($request->getPost());

        $form->isValid();
        //debug
        var_dump($post);

        $post->exchangeArray($form->getData());
        $em = $this->getEntityManager();
        $em->persist($post);
        $em->flush();
        $this->flashMessenger()->addSuccessMessage('Post Saved');
        return $this->redirect()->toRoute('post');
    }
     return new ViewModel(array(
        'post' => $post,
        'form' => $form
    ));
}

我将如何解决这个问题,我不明白它为什么不抱怨 id 但为此它会抱怨。

更新 ** 类别实体 ORM 注释

/**
 *
 * @ORM\ManyToOne(targetEntity="Category")
 * @ORM\JoinColumn(name="category_id", referencedColumnName="id")
 */
private $category;

你在这个 fieldset 上的水龙头设置是什么?

例如;

$this->setHydrator(new DoctrineHydrator($em, 'Blog\Entity\Category'))
             ->setObject(
                 new Category()
             );