diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php
index 02792b98d..6c68f5b2a 100644
--- a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php
+++ b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php
@@ -649,37 +649,47 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface
//
__seq in PostgreSQL for SERIAL columns.
// Not pretty but necessary and the simplest solution that currently works.
$sequenceName = null;
+
if($this->targetPlatform instanceof Platforms\PostgreSQLPlatform) {
$fieldName = $class->getSingleIdentifierFieldName();
$columnName = $class->getSingleIdentifierColumnName();
$quoted = isset($class->fieldMappings[$fieldName]['quoted']) || isset($class->table['quoted']);
$sequenceName = $class->getTableName() . '_' . $columnName . '_seq';
- $definition = array(
+ $definition = array(
'sequenceName' => $this->targetPlatform->fixSchemaElementName($sequenceName)
);
+
if ($quoted) {
$definition['quoted'] = true;
}
+
$sequenceName = $this->em->getConfiguration()->getQuoteStrategy()->getSequenceName($definition, $class, $this->targetPlatform);
}
+
$class->setIdGenerator(new \Doctrine\ORM\Id\IdentityGenerator($sequenceName));
break;
case ClassMetadata::GENERATOR_TYPE_SEQUENCE:
// If there is no sequence definition yet, create a default definition
$definition = $class->sequenceGeneratorDefinition;
+
if ( ! $definition) {
$fieldName = $class->getSingleIdentifierFieldName();
$columnName = $class->getSingleIdentifierColumnName();
$quoted = isset($class->fieldMappings[$fieldName]['quoted']) || isset($class->table['quoted']);
$sequenceName = $class->getTableName() . '_' . $columnName . '_seq';
- $definition['sequenceName'] = $this->targetPlatform->fixSchemaElementName($sequenceName);
- $definition['allocationSize'] = 1;
- $definition['initialValue'] = 1;
+ $definition = array(
+ 'sequenceName' => $this->targetPlatform->fixSchemaElementName($sequenceName),
+ 'allocationSize' => 1,
+ 'initialValue' => 1,
+ );
+
if ($quoted) {
$definition['quoted'] = true;
}
+
$class->setSequenceGeneratorDefinition($definition);
}
+
$sequenceGenerator = new \Doctrine\ORM\Id\SequenceGenerator(
$this->em->getConfiguration()->getQuoteStrategy()->getSequenceName($definition, $class, $this->targetPlatform),
$definition['allocationSize']
diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php
index 5e860be10..246a2c9f2 100644
--- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php
+++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php
@@ -1181,11 +1181,11 @@ class ClassMetadataInfo implements ClassMetadata
// Complete fieldName and columnName mapping
if ( ! isset($mapping['columnName'])) {
$mapping['columnName'] = $this->namingStrategy->propertyToColumnName($mapping['fieldName']);
- } else {
- if ($mapping['columnName'][0] == '`') {
- $mapping['columnName'] = trim($mapping['columnName'], '`');
- $mapping['quoted'] = true;
- }
+ }
+
+ if ($mapping['columnName'][0] === '`') {
+ $mapping['columnName'] = trim($mapping['columnName'], '`');
+ $mapping['quoted'] = true;
}
$this->columnNames[$mapping['fieldName']] = $mapping['columnName'];
@@ -1295,8 +1295,8 @@ class ClassMetadataInfo implements ClassMetadata
// Mandatory and optional attributes for either side
if ( ! $mapping['mappedBy']) {
if (isset($mapping['joinTable']) && $mapping['joinTable']) {
- if (isset($mapping['joinTable']['name']) && $mapping['joinTable']['name'][0] == '`') {
- $mapping['joinTable']['name'] = trim($mapping['joinTable']['name'], '`');
+ if (isset($mapping['joinTable']['name']) && $mapping['joinTable']['name'][0] === '`') {
+ $mapping['joinTable']['name'] = trim($mapping['joinTable']['name'], '`');
$mapping['joinTable']['quoted'] = true;
}
}
@@ -1382,14 +1382,14 @@ class ClassMetadataInfo implements ClassMetadata
$joinColumn['referencedColumnName'] = $this->namingStrategy->referenceColumnName();
}
- if ($joinColumn['name'][0] == '`') {
+ if ($joinColumn['name'][0] === '`') {
$joinColumn['name'] = trim($joinColumn['name'], '`');
$joinColumn['quoted'] = true;
}
- if ($joinColumn['referencedColumnName'][0] == '`') {
- $joinColumn['referencedColumnName'] = trim($joinColumn['referencedColumnName'], '`');
- $joinColumn['quoted'] = true;
+ if ($joinColumn['referencedColumnName'][0] === '`') {
+ $joinColumn['referencedColumnName'] = trim($joinColumn['referencedColumnName'], '`');
+ $joinColumn['quoted'] = true;
}
$mapping['sourceToTargetKeyColumns'][$joinColumn['name']] = $joinColumn['referencedColumnName'];
@@ -1477,14 +1477,14 @@ class ClassMetadataInfo implements ClassMetadata
$joinColumn['referencedColumnName'] = $this->namingStrategy->referenceColumnName();
}
- if ($joinColumn['name'][0] == '`') {
+ if ($joinColumn['name'][0] === '`') {
$joinColumn['name'] = trim($joinColumn['name'], '`');
$joinColumn['quoted'] = true;
}
- if ($joinColumn['referencedColumnName'][0] == '`') {
- $joinColumn['referencedColumnName'] = trim($joinColumn['referencedColumnName'], '`');
- $joinColumn['quoted'] = true;
+ if ($joinColumn['referencedColumnName'][0] === '`') {
+ $joinColumn['referencedColumnName'] = trim($joinColumn['referencedColumnName'], '`');
+ $joinColumn['quoted'] = true;
}
if (isset($joinColumn['onDelete']) && strtolower($joinColumn['onDelete']) == 'cascade') {
@@ -1504,14 +1504,14 @@ class ClassMetadataInfo implements ClassMetadata
$inverseJoinColumn['referencedColumnName'] = $this->namingStrategy->referenceColumnName();
}
- if ($inverseJoinColumn['name'][0] == '`') {
+ if ($inverseJoinColumn['name'][0] === '`') {
$inverseJoinColumn['name'] = trim($inverseJoinColumn['name'], '`');
$inverseJoinColumn['quoted'] = true;
}
- if ($inverseJoinColumn['referencedColumnName'][0] == '`') {
- $inverseJoinColumn['referencedColumnName'] = trim($inverseJoinColumn['referencedColumnName'], '`');
- $inverseJoinColumn['quoted'] = true;
+ if ($inverseJoinColumn['referencedColumnName'][0] === '`') {
+ $inverseJoinColumn['referencedColumnName'] = trim($inverseJoinColumn['referencedColumnName'], '`');
+ $inverseJoinColumn['quoted'] = true;
}
if (isset($inverseJoinColumn['onDelete']) && strtolower($inverseJoinColumn['onDelete']) == 'cascade') {
@@ -1984,12 +1984,12 @@ class ClassMetadataInfo implements ClassMetadata
public function setPrimaryTable(array $table)
{
if (isset($table['name'])) {
- if ($table['name'][0] == '`') {
- $this->table['name'] = str_replace("`", "", $table['name']);
- $this->table['quoted'] = true;
- } else {
- $this->table['name'] = $table['name'];
+ if ($table['name'][0] === '`') {
+ $table['name'] = trim($table['name'], '`');
+ $this->table['quoted'] = true;
}
+
+ $this->table['name'] = $table['name'];
}
if (isset($table['indexes'])) {
diff --git a/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php b/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php
index 6d779f0e5..b5a6fc4f1 100644
--- a/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php
+++ b/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php
@@ -30,7 +30,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform;
*/
class DefaultQuoteStrategy implements QuoteStrategy
{
-
/**
* {@inheritdoc}
*/
@@ -108,7 +107,8 @@ class DefaultQuoteStrategy implements QuoteStrategy
// Association defined as Id field
$joinColumns = $class->associationMappings[$fieldName]['joinColumns'];
$assocQuotedColumnNames = array_map(
- function ($joinColumn) use ($platform) {
+ function ($joinColumn) use ($platform)
+ {
return isset($joinColumn['quoted'])
? $platform->quoteIdentifier($joinColumn['name'])
: $joinColumn['name'];
diff --git a/lib/Doctrine/ORM/Mapping/QuoteStrategy.php b/lib/Doctrine/ORM/Mapping/QuoteStrategy.php
index 9e698db22..52e846d99 100644
--- a/lib/Doctrine/ORM/Mapping/QuoteStrategy.php
+++ b/lib/Doctrine/ORM/Mapping/QuoteStrategy.php
@@ -30,7 +30,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform;
*/
interface QuoteStrategy
{
-
/**
* Gets the (possibly quoted) column name for safe use in an SQL statement.
*
diff --git a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php
index 34ed11050..31b761b62 100644
--- a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php
+++ b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php
@@ -463,6 +463,7 @@ class BasicEntityPersister
if ( ! isset($mapping['isOnDeleteCascade'])) {
$joinTableName = $this->quoteStrategy->getJoinTableName($mapping, $this->_class, $this->_platform);
+
$this->_conn->delete($joinTableName, array_combine($keys, $identifier));
if ($selfReferential) {
@@ -486,9 +487,11 @@ class BasicEntityPersister
public function delete($entity)
{
$identifier = $this->_em->getUnitOfWork()->getEntityIdentifier($entity);
+
$this->deleteJoinTableRecords($identifier);
$id = array_combine($this->quoteStrategy->getIdentifierColumnNames($this->_class, $this->_platform), $identifier);
+
$this->_conn->delete($this->quoteStrategy->getTableName($this->_class, $this->_platform), $id);
}
@@ -558,10 +561,10 @@ class BasicEntityPersister
$owningTable = $this->getOwningTable($field);
foreach ($assoc['joinColumns'] as $joinColumn) {
- $sourceColumn = $joinColumn['name'];
- $targetColumn = $joinColumn['referencedColumnName'];
-
+ $sourceColumn = $joinColumn['name'];
+ $targetColumn = $joinColumn['referencedColumnName'];
$quotedColumn = $this->quoteStrategy->getJoinColumnName($joinColumn, $this->_class, $this->_platform);
+
$this->quotedColumns[$sourceColumn] = $quotedColumn;
if ($newVal === null) {
@@ -1113,6 +1116,7 @@ class BasicEntityPersister
$resultColumnName = $this->getSQLColumnAlias($joinColumn['name']);
$columnList .= $this->_getSQLTableAlias($class->name, ($alias == 'r' ? '' : $alias) )
. '.' . $quotedColumn . ' AS ' . $resultColumnName;
+
$this->_rsm->addMetaResult($alias, $resultColumnName, $quotedColumn, isset($assoc['id']) && $assoc['id'] === true);
}
}