Reputation: 391
I have a problem, I have a table (downloads) with two fields: Token (primary key) and value.
I have my entity Downloads with these methods (only show token methods, value works right):
/**
* @var string
*
* @ORM\Column(name="token", type="string", length=45, nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $token;
/**
* Set token
*
* @param string $token
* @return Downloads
*/
public function setToken($token)
{
$this->token = $token;
return $this;
}
/**
* Get token
*
* @return string
*/
public function getToken()
{
return $this->token;
}
But, when I do this in my controller:
$em = $this->getDoctrine()->getManager();
$Download = new Downloads();
$Download->setToken($token);
$Download->setValid($now);
$em->persist($Download);
$em->flush();
Object is well created, but in my database Valid is stored correctly, and token is store empty!!
if I see the values, util $em->flush(); object download has two correct values, but after this, token (primary key) disappear his value.
How can I do?
Upvotes: 0
Views: 509
Reputation: 13
try to remove the @ORM\GeneratedValue (strategy="IDENTITY") because it is the one that causes doctrine to generate value for Token. hope it helps :)
Upvotes: 1
Reputation: 1311
Stupid answer, but have you tried:
It might have to do with Doctrine caching.
Upvotes: 0
Reputation: 935
you have to create auto increment for your columns like this
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
Upvotes: 0