/**
  * @param ClassMetadataBuilder $metadataBuilder
  * @param FieldConfigId        $fieldId
  * @param array                $relation
  * @param string               $relationKey
  */
 protected function buildOneToManyRelation(ClassMetadataBuilder $metadataBuilder, FieldConfigId $fieldId, array $relation, $relationKey)
 {
     $targetEntity = $relation['target_entity'];
     $cascade = !empty($relation['cascade']) ? $relation['cascade'] : [];
     $cascade[] = 'detach';
     $builder = $metadataBuilder->createOneToMany($fieldId->getFieldName(), $targetEntity);
     if (!empty($relation['target_field_id'])) {
         $builder->mappedBy($relation['target_field_id']->getFieldName());
     }
     foreach ($cascade as $cascadeType) {
         $builder->{'cascade' . ucfirst($cascadeType)}();
     }
     $builder->build();
     if (!$relation['owner'] && RelationType::ONE_TO_MANY === ExtendHelper::getRelationType($relationKey) && $this->isDefaultRelationRequired($fieldId)) {
         $this->buildDefaultRelation($metadataBuilder, $fieldId, $targetEntity);
     }
 }
Beispiel #2
0
 public function testGetRelationType()
 {
     $this->assertEquals('manyToOne', ExtendHelper::getRelationType('manyToOne|Test\\Entity|Test\\TargetEntity|testField'));
 }