我正在使用symfony2,我有一个表,我想手动分配ID。Symfony2,手动分配表ID值
在学说的文件,我发现这一点:
标识符生成策略
"NONE: Tells Doctrine that the identifiers are assigned (and thus generated)
by your code. The assignment must take place before a new entity is passed to
EntityManager#persist.
NONE is the same as leaving off the @GeneratedValue entirely."
注重这一点:“一个新的实体传递给恩之前转让必须发生.. “
我该如何做到这一点?
我这样做:
$empleado->setId("989865446");
但它说:
Entity of type Entity\Empleado is missing an assigned ID. The identifier
generation strategy for this entity requires the ID field to be populated before
EntityManager#persist() is called. If you want automatically generated
identifiers instead you need to adjust the metadata mapping accordingly.
编辑:
/**
* @var integer $id
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
*/
private $id;
和
public function setId($id)
{
$this->id = $id;
}
,你能否告诉我们有关的代码围绕'$ empleado-> setId()'? – Problematic 2012-02-25 16:36:26
你是如何实现'setId()'的? – greg0ire 2012-02-25 17:00:26
不用说(但我会说)无论如何,确保你的id属性被称为id。 – Cerad 2012-02-25 21:11:32