2017-10-01 9 views
0

한 데이터베이스에서 다른 데이터베이스로 데이터를 복사하려고합니다. 두 개의 다른 엔티티 관리자 (emLocal, emRemote)로부터 두 명의 고객을 얻습니다.Symfony FosUser를 사용하여 하나의 엔티티 관리자에서 다른 엔티티 관리자로 엔티티 복제

고객 엔터티가 FosUser와 oneToOne 관계에 있음 빈 사용자를 삽입하려고 시도합니다. 관련된 엔티티를 분리하고 모든 릴레이션을 null로 설정하려고해도이 값은입니다.

나는 FosUserBundle 두 엔티티 관리자 나는이 INSERT를 방지 할 수있는 방법

 $remoteCustomer = $order->getCustomer(); 
     $onlineCustomer = $this->emLocal->getRepository("LilWorksStoreBundle:Customer")->findOneBy(array("remoteUser"=>$remoteCustomer->getUser()->getId())); 
     if(!$onlineCustomer){ 
      $onlineCustomer = clone $remoteCustomer; 

     } 
     $this->emLocal->detach($onlineCustomer->getUser()); 
     $onlineCustomer->getUser()->setCustomer(null); 
     $onlineCustomer->setUser(null); 
     $this->emLocal->persist($onlineCustomer); 
     $this->emLocal->flush(); 

와 함께 작동하도록 설계되지 않았 github 읽어?

+2

당신이 하나 개의 요청에서 재사용 할 특히, 교리 복제 기관과주의하시기 바랍니다 표준'clone'은 일반적으로 더 깊은 복사본을 생성하지, 일부 초기화 예상하지 될 수로 등 – LBA

답변

1

다른 Entity Manager을 사용하여 $onlineCustomer을 저장해야한다고 생각합니다.

$this->emOnline->persist($onlineCustomer); 
$this->emOnline->flush();