setId() public method

To force id = 1 in load fixtures.
public setId ( integer $id )
$id integer
Example #1
0
 /**
  * {@inheritdoc}
  */
 public function load(ObjectManager $manager)
 {
     $mediaDocument = new MediaType();
     $mediaDocument->setId(1);
     // force id = 1
     $metadata = $manager->getClassMetaData(get_class($mediaDocument));
     $metadata->setIdGeneratorType(\Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_NONE);
     $mediaDocument->setName('document');
     $manager->persist($mediaDocument);
     $mediaImage = new MediaType();
     $mediaImage->setId(2);
     $mediaImage->setName('image');
     $manager->persist($mediaImage);
     $mediaVideo = new MediaType();
     $mediaVideo->setId(3);
     $mediaVideo->setName('video');
     $manager->persist($mediaVideo);
     $mediaAudio = new MediaType();
     $mediaAudio->setId(4);
     $mediaAudio->setName('audio');
     $manager->persist($mediaAudio);
     $manager->flush();
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function load(ObjectManager $manager)
 {
     // set id manually
     $metadata = $manager->getClassMetaData(MediaType::class);
     $metadata->setIdGenerator(new \Doctrine\ORM\Id\AssignedGenerator());
     $metadata->setIdGeneratorType(\Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_NONE);
     $mediaDocument = new MediaType();
     $mediaDocument->setId(1);
     $mediaDocument = $manager->merge($mediaDocument);
     $mediaDocument->setName('document');
     $mediaImage = new MediaType();
     $mediaImage->setId(2);
     $mediaImage = $manager->merge($mediaImage);
     $mediaImage->setName('image');
     $mediaVideo = new MediaType();
     $mediaVideo->setId(3);
     $mediaVideo = $manager->merge($mediaVideo);
     $mediaVideo->setName('video');
     $mediaAudio = new MediaType();
     $mediaAudio->setId(4);
     $mediaAudio = $manager->merge($mediaAudio);
     $mediaAudio->setName('audio');
     $manager->flush();
 }