Example #1
0
 public function testCreateDoctrineMetadata()
 {
     $options = array('foo' => 'bar');
     $doctrineMetadata = $this->getMock('Oro\\Bundle\\EntityMergeBundle\\Metadata\\DoctrineMetadata');
     $metadata = $this->factory->createFieldMetadata($options, $doctrineMetadata);
     $this->assertInstanceOf('Oro\\Bundle\\EntityMergeBundle\\Metadata\\FieldMetadata', $metadata);
     $this->assertEquals($options, $metadata->all());
     $this->assertEquals($doctrineMetadata, $metadata->getDoctrineMetadata());
 }
Example #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);
         }
     }
 }