Skip to content

Instantly share code, notes, and snippets.

@tyx
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tyx/353de6d6aaf367abd6e6 to your computer and use it in GitHub Desktop.
Save tyx/353de6d6aaf367abd6e6 to your computer and use it in GitHub Desktop.
<?php
$em = $this->getContainer()->get('doctrine')->getManager();
$a = new \Rezzza\VlrModelBundle\Entity\CityTimezone();
$a->setIdentifier('test a');
$a->setGmtoffset(1);
$a->setDstoffset(2);
$a->setRawoffset(3);
$class = get_class($a);
$metadata = $em->getClassMetaData($class);
$generatorType = $metadata->generatorType;
$metadata->setIdGeneratorType(\Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_NONE);
$reflection = new \ReflectionClass($class);
$property = $reflection->getProperty('id');
$property->setAccessible(true);
$property->setValue($a, $id);
$em->persist($a);
$em->flush();
$em->clear();
$metadata->setIdGeneratorType($generatorType);
$b = new \Rezzza\VlrModelBundle\Entity\CityTimezone();
$b->setIdentifier('test b');
$b->setGmtoffset(1);
$b->setDstoffset(2);
$b->setRawoffset(3);
$em->persist($b);
$em->flush();
$em->clear();
// Throw
// [Doctrine\DBAL\DBALException]
// An exception occurred while executing 'INSERT INTO city_timezone (identifier, gmtoffset, dstoffset, rawoffset, id) VALUES (?, ?, ?, ?, ?)' with params ["test b", 1, 2, 3]:
// SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment