2017-09-13 14 views
0

私は50000レコードのために私のdbを埋めるためにDoctrineFixturesBundleを使いました。私は多くの従業員を1つのボスにしたいと思います。データのフィクスチャーは多対1の自己参照

public function load(ObjectManager $manager) 
    { 

     for ($i = 0; $i <= 50000; $i++) { 
      $employee = new Employee(); 
      if($i == 0) { 
       $employee->setPosition('founder'); 
      } 
      $employee->setFullName('new employee'.$i); 
      $employee->setSalary(50000 - $i); 
      $employee->setStartDate(new \DateTime()); 
      if($i > 0) { 
       $employee->setBoss($manager->find(Employee::class,1)); 
       $employee->setPosition('boss'); 
      } elseif ($i >= 1000) { 
       $id = rand(2,1000); 
       $employee->setBoss($manager->find(Employee::class,$id)); 
       $employee->setPosition('top-manager'); 
      } elseif ($i >= 5000) { 
       $id = rand (1000,4999); 
       $employee->setBoss($manager->find(Employee::class,$id)); 
       $employee->setPosition('manager'); 
      } elseif ($i >= 10000){ 
       $id = rand(5000,9999); 
       $employee->setBoss($manager->find(Employee::class,$id)); 
       $employee->setPosition('worker'); 
      } 
      $manager->persist($employee); 

     } 
     $manager->flush(); 
    } 

私のエンティティの従業員:

/** 
    * @var Employee 
    * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Employee") 
    */ 
    private $boss; 
public function setBoss(\AppBundle\Entity\Employee $boss = null) 
    { 
     $this->boss = $boss; 

     return $this; 
    } 

私はこのトリックをどのように行うことができ、私は私のデシベルを満たしたとき、しかし、今、私はboss_idに マイロード機能のみNULL値を持っていますか?私は何を間違えたの?

答えて

0

あなたは

それを使用するときにオブジェクトが作成されていないので、それはthe doc

で説明したように addReferenceを使用しています
関連する問題