Unique constraint (from DoctrineMongoDBBundle) doesn't work with embedded document #295

pierrre opened this Issue Apr 26, 2012 · 9 comments

5 participants


I'm trying to use the "unique validator" from the DoctrineMongoDBBundle, but I get this error:
[BadMethodCallException] Doctrine\ODM\MongoDB\Mapping\ClassMetadataInfo::getAssociationTargetClass($assocName) is not implemented yet.

Am I doing something wrong?

I use Symfony 2.1, and latest bundles/projects versions.


I have more details on this problem:

  • "unique" constraint works with a "normal" document
  • "unique" constraint doesn't work with an embedded document
Doctrine member

Cross-linking: doctrine/DoctrineMongoDBBundle#97

The validator itself looks fine. We likely just need to implement this method (and others if possible) to support the use case.

@jmikola jmikola referenced this issue in doctrine/DoctrineMongoDBBundle Apr 27, 2012

UniqueValidator is invalid with master #77


I have a small question: does it make sense to have an "unique" constraint on an embedded document?

Doctrine member

I think it's possible to define a unique index on an embedded document, which should get picked up when the concrete document (corresponding to a collection) determines its indexes. In that sense, I think it's reasonable for embedded documents to also define unique constraints for those fields.

@jmikola jmikola was assigned May 18, 2012

The real problem is: we can't use the "unique" constraint on a field with an "association" (reference or embed).
Do you think it's easy to implement?


@jwage ping
I'm asking the same questions, will this get looked at soon?

@malarzm malarzm added the needs test label Jan 21, 2016

Issue looks still relevant early 2016.
Can we have a status please?

Doctrine member

@davidloubere: as denoted by label status is "needs test" - please feel free to create a failing unit test and submit is a PR, this will speed up working on the issue

Doctrine member

According to my tests from #1363 DocumentRepository::findBy() already accepted embedded documents and was working properly - call for tests is still open

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment