/**
  * @param ClassMetadata $classMetadata
  * @param array $mapping
  */
 private function remapAssociation(ClassMetadata $classMetadata, array $mapping)
 {
     $newMapping = $this->resolveTargetDocuments[$mapping['targetDocument']];
     $newMapping = array_replace_recursive($mapping, $newMapping);
     $newMapping['fieldName'] = $mapping['fieldName'];
     // clear reference case of duplicate exception
     unset($classMetadata->fieldMappings[$mapping['fieldName']]);
     unset($classMetadata->associationMappings[$mapping['fieldName']]);
     switch ($mapping['association']) {
         case ClassMetadata::REFERENCE_ONE:
             $classMetadata->mapOneReference($newMapping);
             break;
         case ClassMetadata::REFERENCE_MANY:
             $classMetadata->mapManyReference($newMapping);
             break;
         case ClassMetadata::EMBED_ONE:
             $classMetadata->mapOneEmbedded($newMapping);
             break;
         case ClassMetadata::EMBED_MANY:
             $classMetadata->mapManyEmbedded($newMapping);
             break;
     }
 }
 public static function loadMetadata(ClassMetadata $metadata)
 {
     $metadata->setInheritanceType(ClassMetadata::INHERITANCE_TYPE_NONE);
     $metadata->setCollection('cms_users');
     $metadata->addLifecycleCallback('doStuffOnPrePersist', 'prePersist');
     $metadata->addLifecycleCallback('doOtherStuffOnPrePersistToo', 'prePersist');
     $metadata->addLifecycleCallback('doStuffOnPostPersist', 'postPersist');
     $metadata->setDiscriminatorField(array('fieldName' => 'discr'));
     $metadata->setDiscriminatorMap(array('default' => __CLASS__));
     $metadata->setDefaultDiscriminatorValue('default');
     $metadata->mapField(array('id' => true, 'fieldName' => 'id'));
     $metadata->mapField(array('fieldName' => 'version', 'type' => 'int', 'version' => true));
     $metadata->mapField(array('fieldName' => 'lock', 'type' => 'int', 'lock' => true));
     $metadata->mapField(array('fieldName' => 'name', 'name' => 'username', 'type' => 'string'));
     $metadata->mapField(array('fieldName' => 'email', 'type' => 'string'));
     $metadata->mapField(array('fieldName' => 'mysqlProfileId', 'type' => 'integer'));
     $metadata->mapOneReference(array('fieldName' => 'address', 'targetDocument' => 'Doctrine\\ODM\\MongoDB\\Tests\\Mapping\\Address', 'cascade' => array(0 => 'remove')));
     $metadata->mapManyReference(array('fieldName' => 'phonenumbers', 'targetDocument' => 'Doctrine\\ODM\\MongoDB\\Tests\\Mapping\\Phonenumber', 'cascade' => array(1 => 'persist'), 'discriminatorField' => 'discr', 'discriminatorMap' => array('home' => 'HomePhonenumber', 'work' => 'WorkPhonenumber'), 'defaultDiscriminatorValue' => 'home'));
     $metadata->mapManyReference(array('fieldName' => 'morePhoneNumbers', 'name' => 'more_phone_numbers', 'targetDocument' => 'Doctrine\\ODM\\MongoDB\\Tests\\Mapping\\Phonenumber'));
     $metadata->mapManyReference(array('fieldName' => 'groups', 'targetDocument' => 'Doctrine\\ODM\\MongoDB\\Tests\\Mapping\\Group', 'cascade' => array(0 => 'remove', 1 => 'persist', 2 => 'refresh', 3 => 'merge', 4 => 'detach')));
     $metadata->mapOneEmbedded(array('fieldName' => 'embeddedPhonenumber', 'name' => 'embedded_phone_number'));
     $metadata->mapManyEmbedded(array('fieldName' => 'otherPhonenumbers', 'targetDocument' => 'Doctrine\\ODM\\MongoDB\\Tests\\Mapping\\Phonenumber', 'discriminatorField' => 'discr', 'discriminatorMap' => array('home' => 'HomePhonenumber', 'work' => 'WorkPhonenumber'), 'defaultDiscriminatorValue' => 'home'));
     $metadata->addIndex(array('username' => 'desc'), array('unique' => true, 'dropDups' => false));
     $metadata->addIndex(array('email' => 'desc'), array('unique' => true, 'dropDups' => true));
     $metadata->addIndex(array('mysqlProfileId' => 'desc'), array('unique' => true, 'dropDups' => true));
     $metadata->addIndex(array('createdAt' => 'asc'), array('expireAfterSeconds' => 3600));
     $metadata->setShardKey(array('name' => 'asc'), array('unique' => true, 'numInitialChunks' => 4096));
 }
 public static function loadMetadata(ClassMetadata $metadata)
 {
     $metadata->setInheritanceType(ClassMetadata::INHERITANCE_TYPE_NONE);
     $metadata->setCollection('cms_users');
     $metadata->addLifecycleCallback('doStuffOnPrePersist', 'prePersist');
     $metadata->addLifecycleCallback('doOtherStuffOnPrePersistToo', 'prePersist');
     $metadata->addLifecycleCallback('doStuffOnPostPersist', 'postPersist');
     $metadata->mapField(array('id' => true, 'fieldName' => 'id'));
     $metadata->mapField(array('fieldName' => 'name', 'name' => 'username', 'type' => 'string'));
     $metadata->mapField(array('fieldName' => 'email', 'type' => 'string'));
     $metadata->mapField(array('fieldName' => 'mysqlProfileId', 'type' => 'integer'));
     $metadata->mapOneReference(array('fieldName' => 'address', 'targetDocument' => 'Doctrine\\ODM\\MongoDB\\Tests\\Mapping\\Address', 'cascade' => array(0 => 'remove')));
     $metadata->mapManyReference(array('fieldName' => 'phonenumbers', 'targetDocument' => 'Doctrine\\ODM\\MongoDB\\Tests\\Mapping\\Phonenumber', 'cascade' => array(1 => 'persist'), 'discriminatorField' => 'discr', 'discriminatorMap' => array('home' => 'HomePhonenumber', 'work' => 'WorkPhonenumber')));
     $metadata->mapManyReference(array('fieldName' => 'groups', 'targetDocument' => 'Doctrine\\ODM\\MongoDB\\Tests\\Mapping\\Group', 'cascade' => array(0 => 'remove', 1 => 'persist', 2 => 'refresh', 3 => 'merge', 4 => 'detach')));
     $metadata->mapManyEmbedded(array('fieldName' => 'otherPhonenumbers', 'targetDocument' => 'Doctrine\\ODM\\MongoDB\\Tests\\Mapping\\Phonenumber', 'discriminatorField' => 'discr', 'discriminatorMap' => array('home' => 'HomePhonenumber', 'work' => 'WorkPhonenumber')));
     $metadata->addIndex(array('username' => 'desc'), array('unique' => true));
     $metadata->addIndex(array('email' => 'desc'), array('unique' => true, 'dropDups' => true));
     $metadata->addIndex(array('mysqlProfileId' => 'desc'), array('unique' => true, 'dropDups' => true));
 }