I'm working on a project in Symfony2 with a legacy database, that uses a string to have a 6 digit 'franchisee_number' with floating 0's on the front - eg. 000123. When I try to flush the entity, I get an error that shows the SQL statement it tried to do, and it doesn't even try to insert to insert my primary key field. Up until the point of flushing the entity, the 'franchisee_id' is showing up in the entity, so I'm assuming there's a problem with Doctrine not wanting to set the Primary Key, but have it generated.
My problem is very similar to this question: when flush() primary key does not get inserted, but I've tried the answers listed, and they don't work.
Here is the code from my Entity for the 'franchisee_number' field:
/**
* @var string
* @ORM\Id
* @ORM\GeneratedValue(strategy="NONE")
* @ORM\Column(name="franchisee_number", type="string", length=255, nullable=false)
*
*/
private $franchiseeNumber;
I assumed that @ORM\GeneratedValue(strategy="NONE")
would tell doctrine I'm inserting my own value into the field, and not trying to generate it.
And my controller code
public function createAction(Request $request)
{
$this->denyAccessUnlessGranted('ROLE_ADMIN');
$entity = new Accounts();
$form = $this->createCreateForm($entity);
$form->handleRequest($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager('inertia');
$em->persist($entity);
$em->flush();
return $this->redirect($this->generateUrl('accounts_show', array('id' => $entity->getId())));
}
return $this->render('InertiaBundle:Accounts:new.html.twig', array(
'entity' => $entity,
'form' => $form->createView(),
));
}
I also made sure there were no xml config files in the Bundle/Resources/config/doctrine directory.
Thanks in advance for the help!