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


PHP ClassMetadata::hasAssociation方法代码示例

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


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

示例1: getAssociationMapping

 /** {@inheritdoc} */
 public function getAssociationMapping($name)
 {
     if (!$this->classMetadata->hasAssociation($name)) {
         throw new MetadataException("Association '{$name}' not found in class '{$this->getClass()}'.");
     }
     return $this->classMetadata->getAssociationMapping($name);
 }
开发者ID:mike227,项目名称:n-forms,代码行数:8,代码来源:ClassMetadata.php

示例2: readFieldDefs

 private function readFieldDefs(array $params)
 {
     foreach ($params as $key => $def) {
         if ($this->metadata->hasField($key) || $this->metadata->hasAssociation($key)) {
             $this->fieldDefs[$key] = $this->normalizeFieldDef($def);
         } else {
             throw new Exception('No such field in ' . $this->entityType . ': ' . $key);
         }
     }
 }
开发者ID:breerly,项目名称:factory-girl-php,代码行数:10,代码来源:EntityDef.php

示例3: updateTranslationMetadata

 protected function updateTranslationMetadata(ClassMetadata $metadata)
 {
     if (!$metadata->hasAssociation('translatable')) {
         $metadata->mapManyToOne(['fieldName' => 'translatable', 'inversedBy' => 'translations', 'fetch' => $this->translationFetchMode, 'joinColumns' => [['name' => 'translatable_id', 'referencedColumnName' => 'id', 'onDelete' => 'CASCADE']], 'targetEntity' => substr($metadata->name, 0, -strlen('Translation'))]);
         $metadata->table['uniqueConstraints'][] = ['name' => 'unique_translation', 'columns' => ['translatable_id', 'locale']];
     }
 }
开发者ID:nkt,项目名称:translate-bundle,代码行数:7,代码来源:SchemaEventSubscriber.php

示例4: __call

 /**
  * Adds support for magic finders.
  *
  * @return array|object The found entity/entities.
  * @throws BadMethodCallException  If the method called is an invalid find* method
  *                                 or no find* method at all and therefore an invalid
  *                                 method call.
  */
 public function __call($method, $arguments)
 {
     switch (true) {
         case 0 === strpos($method, 'findBy'):
             $by = substr($method, 6);
             $method = 'findBy';
             break;
         case 0 === strpos($method, 'findOneBy'):
             $by = substr($method, 9);
             $method = 'findOneBy';
             break;
         default:
             throw new \BadMethodCallException("Undefined method '{$method}'. The method name must start with " . "either findBy or findOneBy!");
     }
     if (empty($arguments)) {
         throw ORMException::findByRequiresParameter($method . $by);
     }
     $fieldName = lcfirst(\Doctrine\Common\Util\Inflector::classify($by));
     if ($this->_class->hasField($fieldName) || $this->_class->hasAssociation($fieldName)) {
         switch (count($arguments)) {
             case 1:
                 return $this->{$method}(array($fieldName => $arguments[0]));
             case 2:
                 return $this->{$method}(array($fieldName => $arguments[0]), $arguments[1]);
             case 3:
                 return $this->{$method}(array($fieldName => $arguments[0]), $arguments[1], $arguments[2]);
             case 4:
                 return $this->{$method}(array($fieldName => $arguments[0]), $arguments[1], $arguments[2], $arguments[3]);
             default:
                 // Do nothing
         }
     }
     throw ORMException::invalidFindByCall($this->_entityName, $fieldName, $method . $by);
 }
开发者ID:paulodacosta,项目名称:LearnFlash,代码行数:42,代码来源:EntityRepository.php

示例5: setFieldLimit

 /**
  * @param array         $fieldConfig
  * @param ClassMetadata $metadata
  * @param string        $fieldName
  * @param int           $limit
  */
 protected function setFieldLimit(array &$fieldConfig, ClassMetadata $metadata, $fieldName, $limit)
 {
     if ($metadata->hasAssociation($fieldName)) {
         if (!array_key_exists(ConfigUtil::MAX_RESULTS, $fieldConfig) && $metadata->isCollectionValuedAssociation($fieldName)) {
             $fieldConfig[ConfigUtil::MAX_RESULTS] = $limit;
         }
         $this->setLimits($fieldConfig, $metadata->name, $limit);
     }
 }
开发者ID:startupz,项目名称:platform-1,代码行数:15,代码来源:SetMaxRelatedEntities.php

示例6: mapTranslation

 private function mapTranslation(ClassMetadata $classMetadata)
 {
     if (!$classMetadata->hasAssociation('translatable')) {
         $classMetadata->mapManyToOne(['fieldName' => 'translatable', 'inversedBy' => 'translations', 'joinColumns' => [['name' => 'translatable_id', 'referencedColumnName' => 'id', 'onDelete' => 'CASCADE']], 'targetEntity' => substr($classMetadata->name, 0, -11)]);
     }
     $name = $classMetadata->getTableName() . '_unique_translation';
     if (!$this->hasUniqueTranslationConstraint($classMetadata, $name)) {
         $classMetadata->setPrimaryTable(['uniqueConstraints' => [['name' => $name, 'columns' => ['translatable_id', 'locale']]]]);
     }
 }
开发者ID:nvdnkpr,项目名称:DoctrineBehaviors,代码行数:10,代码来源:TranslatableListener.php

示例7: resolveMagicCall

 /**
  * Resolves a magic method call to the proper existent method at `EntityRepository`.
  *
  * @param string $method    The method to call
  * @param string $by        The property name used as condition
  * @param array  $arguments The arguments to pass at method call
  *
  * @throws ORMException If the method called is invalid or the requested field/association does not exist
  *
  * @return mixed
  */
 private function resolveMagicCall($method, $by, array $arguments)
 {
     if (!$arguments) {
         throw ORMException::findByRequiresParameter($method . $by);
     }
     $fieldName = lcfirst(Inflector::classify($by));
     if (!($this->_class->hasField($fieldName) || $this->_class->hasAssociation($fieldName))) {
         throw ORMException::invalidMagicCall($this->_entityName, $fieldName, $method . $by);
     }
     return $this->{$method}([$fieldName => $arguments[0]], ...array_slice($arguments, 1));
 }
开发者ID:AdactiveSAS,项目名称:doctrine2,代码行数:22,代码来源:EntityRepository.php

示例8: getAssociationMapping

 public static function getAssociationMapping(ClassMetadata $classMetadata, $name, $type = NULL)
 {
     if (!$classMetadata->hasAssociation($name)) {
         return NULL;
     }
     $mapping = $classMetadata->getAssociationMapping($name);
     $type = $type ? (array) $type : NULL;
     if ($type === NULL || in_array($mapping['type'], $type, TRUE)) {
         return $mapping;
     }
     return NULL;
 }
开发者ID:librette,项目名称:doctrine-forms,代码行数:12,代码来源:MetadataHelpers.php

示例9: mapTranslation

 /**
  * @param ClassMetadata $classMetadata
  * @throws \Doctrine\ORM\Mapping\MappingException
  */
 private function mapTranslation(ClassMetadata $classMetadata)
 {
     if (!$classMetadata->hasAssociation('translatable')) {
         $classMetadata->mapManyToOne(array('fieldName' => 'translatable', 'inversedBy' => 'translations', 'fetch' => $this->translationFetchMode, 'joinColumns' => array(array('name' => 'translatable_id', 'referencedColumnName' => 'id', 'onDelete' => 'CASCADE', 'nullable' => false)), 'targetEntity' => $this->getClassName($classMetadata)));
     }
     if (!$classMetadata->hasField('locale')) {
         $classMetadata->mapField(array('fieldName' => 'locale', 'type' => 'string', 'length' => 10));
     }
     $name = $classMetadata->getTableName() . '_unique_translation';
     if (!$this->hasUniqueTranslationConstraint($classMetadata, $name)) {
         $classMetadata->setPrimaryTable(array('uniqueConstraints' => array(array('name' => $name, 'columns' => array('translatable_id', 'locale')))));
     }
 }
开发者ID:jewome62,项目名称:DoctrineIntl,代码行数:17,代码来源:TranslatableSubscriber.php

示例10: clearProperties

 /**
  * @param ClassMetadata $metadata
  * @param object|array  $entity
  * @param array         $properties
  */
 protected function clearProperties(ClassMetadata $metadata, &$entity, array $properties)
 {
     if (is_array($entity)) {
         foreach ($properties as $property) {
             $entity[$property] = null;
         }
     } else {
         foreach ($properties as $property) {
             if ($metadata->hasField($property) || $metadata->hasAssociation($property)) {
                 $metadata->setFieldValue($entity, $property, null);
             }
         }
     }
 }
开发者ID:vend,项目名称:doxport,代码行数:19,代码来源:QueryAction.php

示例11: getRelation

 /**
  * @param ClassMetadata $meta
  * @param object $entity
  * @param string $field
  * @return bool|object
  */
 private function getRelation(ClassMetadata $meta, $entity, $field)
 {
     if (!$meta->hasAssociation($field) || !$meta->isSingleValuedAssociation($field)) {
         return FALSE;
     }
     // todo: allow access using property or method
     $relation = $meta->getFieldValue($entity, $field);
     if ($relation instanceof Collection) {
         return FALSE;
     }
     if ($relation === NULL) {
         $class = $meta->getAssociationTargetClass($field);
         $relationMeta = $this->mapper->getEntityManager()->getClassMetadata($class);
         $relation = $relationMeta->newInstance();
         $meta->setFieldValue($entity, $field, $relation);
     }
     return $relation;
 }
开发者ID:kuba1999,项目名称:DoctrineForms,代码行数:24,代码来源:ToOne.php

示例12: __call

 /**
  * Adds support for magic finders.
  *
  * @return array|object The found entity/entities.
  * @throws BadMethodCallException  If the method called is an invalid find* method
  *                                 or no find* method at all and therefore an invalid
  *                                 method call.
  */
 public function __call($method, $arguments)
 {
     if (substr($method, 0, 6) == 'findBy') {
         $by = substr($method, 6, strlen($method));
         $method = 'findBy';
     } else {
         if (substr($method, 0, 9) == 'findOneBy') {
             $by = substr($method, 9, strlen($method));
             $method = 'findOneBy';
         } else {
             throw new \BadMethodCallException("Undefined method '{$method}'. The method name must start with " . "either findBy or findOneBy!");
         }
     }
     if (!isset($arguments[0])) {
         // we dont even want to allow null at this point, because we cannot (yet) transform it into IS NULL.
         throw ORMException::findByRequiresParameter($method . $by);
     }
     $fieldName = lcfirst(\Doctrine\Common\Util\Inflector::classify($by));
     if ($this->_class->hasField($fieldName) || $this->_class->hasAssociation($fieldName)) {
         return $this->{$method}(array($fieldName => $arguments[0]));
     } else {
         throw ORMException::invalidFindByCall($this->_entityName, $fieldName, $method . $by);
     }
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:32,代码来源:EntityRepository.php

示例13: 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

示例14: setFieldCustomizationHandler

 /**
  * @param ConfigContext $context
  * @param array         $fieldConfig
  * @param ClassMetadata $metadata
  * @param string        $fieldName
  * @param string        $rootEntityClass
  * @param string        $fieldPath
  */
 protected function setFieldCustomizationHandler(ConfigContext $context, array &$fieldConfig, ClassMetadata $metadata, $fieldName, $rootEntityClass, $fieldPath)
 {
     if (isset($fieldConfig[ConfigUtil::FIELDS]) && is_array($fieldConfig[ConfigUtil::FIELDS]) && $metadata->hasAssociation($fieldName)) {
         if (!isset($definition[ConfigUtil::POST_SERIALIZE])) {
             $fieldConfig[ConfigUtil::POST_SERIALIZE] = $this->getCustomizationHandler($context, $rootEntityClass, $fieldPath, $metadata->getAssociationTargetClass($fieldName));
         }
         $this->processFields($context, $fieldConfig[ConfigUtil::FIELDS], $rootEntityClass, $metadata, $fieldPath);
     }
 }
开发者ID:Maksold,项目名称:platform,代码行数:17,代码来源:SetDataItemCustomizationHandler.php

示例15: isAssociation

 /**
  * Checks if the given field is a mapped association
  *
  * @param string $fieldName
  *
  * @return boolean
  */
 public function isAssociation($fieldName)
 {
     return $this->metadata->hasAssociation($fieldName);
 }
开发者ID:nmallare,项目名称:platform,代码行数:11,代码来源:EntityMetadata.php


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