当前位置: 首页>>代码示例>>PHP>>正文


PHP ClassMetadata::getSingleAssociationJoinColumnName方法代码示例

本文整理汇总了PHP中Doctrine\ORM\Mapping\ClassMetadata::getSingleAssociationJoinColumnName方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassMetadata::getSingleAssociationJoinColumnName方法的具体用法?PHP ClassMetadata::getSingleAssociationJoinColumnName怎么用?PHP ClassMetadata::getSingleAssociationJoinColumnName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Doctrine\ORM\Mapping\ClassMetadata的用法示例。


在下文中一共展示了ClassMetadata::getSingleAssociationJoinColumnName方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: mapTranslation

 /**
  * Add mapping data to a translation entity.
  *
  * @param ClassMetadata $metadata
  */
 private function mapTranslation(ClassMetadata $metadata)
 {
     // In the case A -> B -> TranslationInterface, B might not have mapping defined as it
     // is probably defined in A, so in that case, we just return.
     if (!isset($this->configs[$metadata->name])) {
         return;
     }
     $metadata->mapManyToOne(array('fieldName' => 'translatable', 'targetEntity' => $this->configs[$metadata->name]['model'], 'inversedBy' => 'translations', 'joinColumns' => array(array('name' => 'translatable_id', 'referencedColumnName' => 'id', 'onDelete' => 'CASCADE', 'nullable' => false))));
     if (!$metadata->hasField('locale')) {
         $metadata->mapField(array('fieldName' => 'locale', 'type' => 'string', 'nullable' => false));
     }
     // Map unique index.
     $columns = array($metadata->getSingleAssociationJoinColumnName('translatable'), 'locale');
     if (!$this->hasUniqueConstraint($metadata, $columns)) {
         $constraints = isset($metadata->table['uniqueConstraints']) ? $metadata->table['uniqueConstraints'] : array();
         $constraints[$metadata->getTableName() . '_uniq_trans'] = array('columns' => $columns);
         $metadata->setPrimaryTable(array('uniqueConstraints' => $constraints));
     }
 }
开发者ID:aleherse,项目名称:Sylius,代码行数:24,代码来源:ORMTranslatableListener.php

示例2: getDefiningClass

 /**
  * Get the class metadata that is responsible for the definition of the referenced column name.
  *
  * Previously this was a simple task, but with DDC-117 this problem is actually recursive. If its
  * not a simple field, go through all identifier field names that are associations recursivly and
  * find that referenced column name.
  *
  * TODO: Is there any way to make this code more pleasing?
  *
  * @param ClassMetadata $class
  * @param string $referencedColumnName
  * @return array(ClassMetadata, referencedFieldName)
  */
 private function getDefiningClass($class, $referencedColumnName)
 {
     $referencedFieldName = $class->getFieldName($referencedColumnName);
     if ($class->hasField($referencedFieldName)) {
         return array($class, $referencedFieldName);
     } else {
         if (in_array($referencedColumnName, $class->getIdentifierColumnNames())) {
             // it seems to be an entity as foreign key
             foreach ($class->getIdentifierFieldNames() as $fieldName) {
                 if ($class->hasAssociation($fieldName) && $class->getSingleAssociationJoinColumnName($fieldName) == $referencedColumnName) {
                     return $this->getDefiningClass($this->em->getClassMetadata($class->associationMappings[$fieldName]['targetEntity']), $class->getSingleAssociationReferencedJoinColumnName($fieldName));
                 }
             }
         }
     }
     return null;
 }
开发者ID:Herriniaina,项目名称:iVarotra,代码行数:30,代码来源:SchemaTool.php

示例3: mapTranslation

 /**
  * Add mapping data to a translation entity
  *
  * @param ClassMetadata $mapping
  * @return void
  */
 private function mapTranslation(ClassMetadata $mapping)
 {
     $metadata = $this->getTranslatableMetadata($mapping->name);
     // Map translatable relation
     if (!$mapping->hasAssociation($metadata->translatable->name)) {
         $targetMetadata = $this->getTranslatableMetadata($metadata->targetEntity);
         $mapping->mapManyToOne(array('fieldName' => $metadata->translatable->name, 'targetEntity' => $metadata->targetEntity, 'inversedBy' => $targetMetadata->translations->name, 'joinColumns' => array(array('name' => 'translatable_id', 'referencedColumnName' => 'id', 'onDelete' => 'CASCADE', 'nullable' => false))));
     }
     // Map locale field
     if (!$mapping->hasField($metadata->locale->name)) {
         $mapping->mapField(array('fieldName' => $metadata->locale->name, 'type' => 'string'));
     }
     // Map unique index
     $columns = array($mapping->getSingleAssociationJoinColumnName($metadata->translatable->name), $metadata->locale->name);
     if (!$this->hasUniqueConstraint($mapping, $columns)) {
         $constraints = isset($mapping->table['uniqueConstraints']) ? $mapping->table['uniqueConstraints'] : array();
         $constraints[$mapping->getTableName() . '_uniq_trans'] = array('columns' => $columns);
         $mapping->setPrimaryTable(array('uniqueConstraints' => $constraints));
     }
 }
开发者ID:prezent,项目名称:doctrine-translatable,代码行数:26,代码来源:TranslatableListener.php

示例4: mapTranslation

 /**
  * Add mapping data to a translation entity.
  *
  * @param ClassMetadata $metadata
  */
 private function mapTranslation(ClassMetadata $metadata)
 {
     $className = $metadata->name;
     try {
         $resourceMetadata = $this->resourceMetadataRegistry->getByClass($className);
     } catch (\InvalidArgumentException $exception) {
         return;
     }
     /** @var MetadataInterface $translatableResourceMetadata */
     $translatableResourceMetadata = $this->resourceMetadataRegistry->get(str_replace('_translation', '', $resourceMetadata->getAlias()));
     $metadata->mapManyToOne(['fieldName' => 'translatable', 'targetEntity' => $translatableResourceMetadata->getClass('model'), 'inversedBy' => 'translations', 'joinColumns' => [['name' => 'translatable_id', 'referencedColumnName' => 'id', 'onDelete' => 'CASCADE', 'nullable' => false]]]);
     if (!$metadata->hasField('locale')) {
         $metadata->mapField(['fieldName' => 'locale', 'type' => 'string', 'nullable' => false]);
     }
     // Map unique index.
     $columns = [$metadata->getSingleAssociationJoinColumnName('translatable'), 'locale'];
     if (!$this->hasUniqueConstraint($metadata, $columns)) {
         $constraints = isset($metadata->table['uniqueConstraints']) ? $metadata->table['uniqueConstraints'] : [];
         $constraints[$metadata->getTableName() . '_uniq_trans'] = ['columns' => $columns];
         $metadata->setPrimaryTable(['uniqueConstraints' => $constraints]);
     }
 }
开发者ID:sylius,项目名称:sylius,代码行数:27,代码来源:ORMTranslatableListener.php


注:本文中的Doctrine\ORM\Mapping\ClassMetadata::getSingleAssociationJoinColumnName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。