public function testFieldsMetadata()
 {
     $fieldName = 'test';
     $fieldMetadata = $this->createFieldMetadata($fieldName);
     $this->metadata->addFieldMetadata($fieldMetadata);
     $this->assertEquals(array($fieldName => $fieldMetadata), $this->metadata->getFieldsMetadata());
 }
Beispiel #2
0
 /**
  * @param EntityMetadata $entityMetadata
  * @param ClassMetadata $classMetadata
  * @param string $className
  */
 protected function addDoctrineInverseAssociations(EntityMetadata $entityMetadata, ClassMetadata $classMetadata, $className)
 {
     $allMetadata = $this->doctrineHelper->getAllMetadata();
     foreach ($allMetadata as $metadata) {
         if ($metadata == $classMetadata) {
             // Skip own class metadata
             continue;
         }
         $currentClassName = $metadata->getName();
         $associationMappings = $metadata->getAssociationsByTargetClass($className);
         foreach ($associationMappings as $fieldName => $associationMapping) {
             if (isset($associationMapping['type']) && $associationMapping['type'] === ClassMetadataInfo::MANY_TO_MANY || isset($associationMapping['mappedBy'])) {
                 // Skip "mapped by" and many-to-many as it's included on other side.
                 continue;
             }
             $associationMapping['mappedBySourceEntity'] = false;
             $mergeModes = [MergeModes::UNITE];
             if ($associationMapping['type'] === ClassMetadataInfo::ONE_TO_ONE) {
                 // for fields with ONE_TO_ONE relation Unite strategy is impossible, so Replace is used
                 $mergeModes = [MergeModes::REPLACE];
             }
             $fieldMetadata = $this->metadataFactory->createFieldMetadata(array('field_name' => $this->createInverseAssociationFieldName($currentClassName, $fieldName), 'merge_modes' => $mergeModes, 'source_field_name' => $fieldName, 'source_class_name' => $currentClassName), $associationMapping);
             $entityMetadata->addFieldMetadata($fieldMetadata);
         }
     }
 }