/**
  * @param ConfigInterface $fieldConfig
  */
 protected function createSelfRelation(ConfigInterface $fieldConfig)
 {
     $selfFieldId = $this->createFieldConfigId($fieldConfig);
     $selfIsOwnerSide = true;
     $targetFieldId = false;
     $targetEntityClass = $fieldConfig->get('target_entity');
     if (in_array($selfFieldId->getFieldType(), RelationType::$toManyRelations, true)) {
         $relationFieldName = ExtendHelper::buildToManyRelationTargetFieldName($selfFieldId->getClassName(), $selfFieldId->getFieldName());
         if ($selfFieldId->getFieldType() === RelationType::ONE_TO_MANY) {
             $selfIsOwnerSide = false;
         }
         $targetFieldId = new FieldConfigId('extend', $targetEntityClass, $relationFieldName, ExtendHelper::getReverseRelationType($selfFieldId->getFieldType()));
     }
     $relationKey = $fieldConfig->get('relation_key');
     $selfConfig = $this->getEntityConfig($selfFieldId->getClassName());
     $selfRelation = ['field_id' => $selfFieldId, 'owner' => $selfIsOwnerSide, 'target_entity' => $targetEntityClass, 'target_field_id' => $targetFieldId];
     if ($fieldConfig->has('cascade')) {
         $selfRelation['cascade'] = $fieldConfig->get('cascade');
     }
     $selfRelations = $selfConfig->get('relation', false, []);
     $selfRelations[$relationKey] = $selfRelation;
     $selfConfig->set('relation', $selfRelations);
     $this->configManager->persist($selfConfig);
     $targetConfig = $this->getEntityConfig($targetEntityClass);
     $targetRelation = ['field_id' => $targetFieldId, 'owner' => !$selfIsOwnerSide, 'target_entity' => $selfFieldId->getClassName(), 'target_field_id' => $selfFieldId];
     $targetRelations = $targetConfig->get('relation', false, []);
     $targetRelations[$relationKey] = $targetRelation;
     $targetConfig->set('relation', $targetRelations);
     $this->configManager->persist($targetConfig);
 }
Beispiel #2
0
 /**
  * @dataProvider buildToManyRelationTargetFieldNameProvider
  */
 public function testBuildToManyRelationTargetFieldName($entityClassName, $fieldName, $expected)
 {
     $this->assertEquals($expected, ExtendHelper::buildToManyRelationTargetFieldName($entityClassName, $fieldName));
 }
 /**
  * Builds a column name for a one-to-many relation
  *
  * @param string $entityClassName
  * @param string $associationName
  * @return string
  */
 public function generateOneToManyRelationColumnName($entityClassName, $associationName)
 {
     return sprintf('%s%s', ExtendHelper::buildToManyRelationTargetFieldName($entityClassName, $associationName), self::RELATION_COLUMN_SUFFIX);
 }