Symfony 2.6 응용 프로그램과 doctrine-odm-bundle 3.0.2 (doctrine-odm : 1.1.2, mongodb : 1.4.0)를 사용하고 있습니다.문서를 지속적으로 저장하면 다음 식별자 값이 반환되지 않습니다. (ALNUM strategry)
내 문서의 속성이 referenceMany
이고 referenceOne
이고 새 인스턴스를 만들 때 입력란을 채우고 계속하면 처음부터 잘됩니다. 내가 참조 문서 (들) 또는없이 거의 거의 빈 문서를 만들 수없고 잘 작동합니다. 어떤 점에서 나는 데이터베이스에 새 항목을 추가하려고하고 오류가 점점 오전 :
E11000 duplicate key error collection: test.Product index: _id_ dup key: { : 0 }
메시지는 분명하다을 - 나는 문서가 ID = 0 컬렉션에 추가되므로 두 번째가 있다고 볼 수 있습니다 갈 수 없어 -> 중복 항목. 그러나 왜 갑자기 id가 "0"을 반환하기 시작 했습니까? 그럼에도 불구하고, 나는 doctrine_increment_ids
id에 대한 콜렉션 카운터가 증가하고 있는지 확인했다. 그러나 $product->getId()
은 지속 후에 "0"이됩니다.
데이터베이스를 삭제하고 처음부터 다시 시작하면 작동하지만 여전히 컬렉션에 새 제품을 추가 할 수 있습니다. 12 개의 제품을 성공적으로 만들었다 고 가정 해 보겠습니다. id = 0 인 문서가 컬렉션에 유지되는 결과가 13 번째로 생성됩니다. 중복 오류로 인해 14 번째 오류가 발생합니다.
어디서 문제가 발생했는지 문제를 해결하거나 제안 하시겠습니까?
PS> (이 시점에서) Symfony2를 업그레이드하는 것을 고려하고 있지 않습니다. 새로운 symfony2에 의존하는 doctrine-odm-bundle도 아닙니다. 마이그레이션 작업이 상당히 많이 걸리므로 문제가 해결 될지 잘 모르겠습니다. 발행물. 먼저 근본 원인을 찾고 싶습니다.
// Document Product
/**
* @MongoDB\Document
* @MongoDB\HasLifecycleCallbacks
*/
class Product
{
/** @MongoDB\Id(strategy="ALNUM", type="int") */
protected $id;
/**
* @Gedmo\ReferenceOne(type="entity", class="Entity\User", inversedBy="products", identifier="userId")
*/
protected $user;
/**
* @MongoDB\Field(name="user_id", type="int")
*/
protected $userId;
/**
* @MongoDB\ReferenceMany(
* targetDocument="Picture",
* discriminatorMap={"file" = "File", "picture" = "Picture"},
* discriminatorField="discr",
* defaultDiscriminatorValue="picture"
*)
* @Assert\Valid
*/
protected $pictures;
...
}
// Entity User
/**
* User entity
* @ORM\Entity
* @ORM\Table(name="users")
*/
class User
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var ArrayCollection $textures
*
* @Gedmo\ReferenceMany(type="document", class="Document\Product", mappedBy="user")
*/
protected $products;
...
}
// Document Picture
/**
* @MongoDB\Document
* @MongoDB\InheritanceType("SINGLE_COLLECTION")
* @MongoDB\DiscriminatorField("discr")
* @MongoDB\DiscriminatorMap({"file" = "File", "picture" = "Picture"})
* @MongoDB\DefaultDiscriminatorValue("picture")
* @MongoDB\HasLifecycleCallbacks
*/
class Picture
{
/**
*
* @MongoDB\Id(strategy="ALNUM", type="int")
*/
protected $id;
/**
* @MongoDB\ReferenceOne(targetDocument="Product")
*
* @var Product $product
*/
protected $product;
...
}