本文整理汇总了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));
}
}
示例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;
}
示例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));
}
}
示例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]);
}
}