2012-10-06 1 views
1

문서의 id 필드에 대한 교리 ODM와 주석을 설정할 때 기본 MongoId 방법과 같이 다른 키 생성 전략을 지정할 수 있습니다Doctrine ODM에 대한 기본 ID 전략을 설정할 수 있습니까?

/** @ODM\Document(collection="documents") */ 
class Document 
{ 
    /** 
    * @ODM\Id(strategy="UUID") 
    */ 
    protected $id; 
} 

이 모든 새 문서에이 전략을 지정해야합니다을 매핑 설정. 전체 응용 프로그램의 기본 전략을 변경할 수 있습니까? 어쩌면 연결 수준의 구성 옵션을 통해?

+0

당신은 당신의 질문에 대한 답을 찾았어요? –

답변

0

상속이 충분하지 않습니까?

use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; 

/** @ODM\Document */ 
abstract class AbstractDocument 
{ 
    /** 
    * @ODM\Id(strategy="UUID") 
    */ 
    protected $id; 

    public function getId() 
    { 
     return $this->id; 
    } 
} 

/** @ODM\Document(collection="MyDocument") */ 
class MyDocument extends AbstractDocument {} 

/** @ODM\Document(collection="AnotherDocument") */ 
class AnotherDocument extends AbstractDocument {} 

는 다음을 수행 할 수 있습니다

$myDocument = new MyDocument(); 
$odm->persist($myDocument); 
$odm>flush(); 
$myDocument->getId();