I'm having trouble implementing something in Zf2 and Doctrine2 using MongoDB that's fairly straightforward in Symfony2 and Doctrine2.
I have an Invoice Document where I want to make sure the combination of the Invoice::pattern and Invoice::number is unique. A number can appear multiple times, same as the pattern but the combination of the pattern and invoice number should be unique.
In Symfony2 I would use the bridge
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
@UniqueEntity({"pattern", "number"})
class Invoice
{
...
But this doesn't work in Zf2 for obvious reasons.
My current annotation setup in Zend Framework 2 is
/**
* Class Invoice
* @package Common\Document\Billing
*
* @ODM\Document(
* collection="invoice"
* )
* @ODM\UniqueIndex(keys={"prefix"="asc", "number"="asc"})
* @ODM\ChangeTrackingPolicy("DEFERRED_IMPLICIT")
*/
class Invoice
{
...
But this does actually allow an invoice being persisted with the same pattern and number.