start to work in xxToOne quote
This commit is contained in:
parent
a75c672ee7
commit
2afe24f51c
5
.gitignore
vendored
5
.gitignore
vendored
@ -9,3 +9,8 @@ lib/Doctrine/DBAL
|
||||
/.settings/
|
||||
.buildpath
|
||||
.project
|
||||
/.AppleDouble/
|
||||
/bin/.AppleDouble/
|
||||
/lib/.AppleDouble/
|
||||
/tests/.AppleDouble/
|
||||
/tools/.AppleDouble/
|
@ -64,7 +64,7 @@ class DefaultQuoteStrategy extends QuoteStrategy
|
||||
*/
|
||||
public function getJoinColumnName($columnName, array $association, ClassMetadata $class)
|
||||
{
|
||||
if( !isset($association['joinColumns'])) {
|
||||
if( ! isset($association['joinColumns'])) {
|
||||
return $columnName;
|
||||
}
|
||||
|
||||
@ -80,6 +80,27 @@ class DefaultQuoteStrategy extends QuoteStrategy
|
||||
return $columnName;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getReferencedJoinColumnName($columnName, array $association, ClassMetadata $class)
|
||||
{
|
||||
if( ! isset($association['joinColumns'])) {
|
||||
return $columnName;
|
||||
}
|
||||
|
||||
foreach ($association['joinColumns'] as $joinColumn) {
|
||||
if($joinColumn['referencedColumnName'] === $columnName) {
|
||||
if (isset($joinColumn['quoted'])) {
|
||||
return $this->platform->quoteIdentifier($columnName);
|
||||
}
|
||||
return $columnName;
|
||||
}
|
||||
}
|
||||
|
||||
return $columnName;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
@ -87,6 +87,15 @@ abstract class QuoteStrategy
|
||||
*/
|
||||
abstract public function getJoinColumnName($columnName, array $association, ClassMetadata $class);
|
||||
|
||||
/**
|
||||
* Gets the (possibly quoted) join column name.
|
||||
*
|
||||
* @param array $association
|
||||
* @param ClassMetadata $class
|
||||
* @return string
|
||||
*/
|
||||
abstract public function getReferencedJoinColumnName($columnName, array $association, ClassMetadata $class);
|
||||
|
||||
/**
|
||||
* Gets the (possibly quoted) identifier column names for safe use in an SQL statement.
|
||||
*
|
||||
|
@ -514,7 +514,9 @@ class SchemaTool
|
||||
|
||||
foreach ($joinColumns as $joinColumn) {
|
||||
$columnName = $joinColumn['name'];
|
||||
list($definingClass, $referencedFieldName) = $this->getDefiningClass($class, $joinColumn['referencedColumnName']);
|
||||
$referencedColumnName = $joinColumn['referencedColumnName'];
|
||||
|
||||
list($definingClass, $referencedFieldName) = $this->getDefiningClass($class, $referencedColumnName);
|
||||
|
||||
if (!$definingClass) {
|
||||
throw new \Doctrine\ORM\ORMException(
|
||||
@ -523,12 +525,14 @@ class SchemaTool
|
||||
);
|
||||
}
|
||||
|
||||
$primaryKeyColumns[] = $columnName;
|
||||
$localColumns[] = $columnName;
|
||||
$foreignColumns[] = $joinColumn['referencedColumnName'];
|
||||
$quotedColumnName = $this->quoteStrategy->getJoinColumnName($columnName, $mapping, $class);
|
||||
$quotedRefColumnName = $this->quoteStrategy->getReferencedJoinColumnName($referencedColumnName, $mapping, $class);
|
||||
|
||||
if ( ! $theJoinTable->hasColumn($joinColumn['name'])) {
|
||||
$primaryKeyColumns[] = $quotedColumnName;
|
||||
$localColumns[] = $quotedColumnName;
|
||||
$foreignColumns[] = $quotedRefColumnName;
|
||||
|
||||
if ( ! $theJoinTable->hasColumn($quotedColumnName)) {
|
||||
// Only add the column to the table if it does not exist already.
|
||||
// It might exist already if the foreign key is mapped into a regular
|
||||
// property as well.
|
||||
@ -556,7 +560,7 @@ class SchemaTool
|
||||
}
|
||||
|
||||
if (isset($joinColumn['unique']) && $joinColumn['unique'] == true) {
|
||||
$uniqueConstraints[] = array('columns' => array($columnName));
|
||||
$uniqueConstraints[] = array('columns' => array($quotedColumnName));
|
||||
}
|
||||
|
||||
if (isset($joinColumn['onDelete'])) {
|
||||
|
@ -22,6 +22,8 @@ class Group
|
||||
public $name;
|
||||
|
||||
/**
|
||||
* @var Group
|
||||
*
|
||||
* @ManyToOne(targetEntity="Group", cascade={"persist"})
|
||||
* @JoinColumn(name="`parent-id`", referencedColumnName="`group-id`")
|
||||
*/
|
||||
|
@ -40,7 +40,8 @@ class User
|
||||
* joinColumns={
|
||||
* @JoinColumn(
|
||||
* name="`user-id`",
|
||||
* referencedColumnName="`user-id`")
|
||||
* referencedColumnName="`user-id`"
|
||||
* )
|
||||
* },
|
||||
* inverseJoinColumns={
|
||||
* @JoinColumn(
|
||||
|
@ -16,14 +16,16 @@ class DDC1843Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->markTestIncomplete();
|
||||
parent::setUp();
|
||||
|
||||
$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger);
|
||||
//$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger);
|
||||
|
||||
try {
|
||||
$this->_schemaTool->createSchema(array(
|
||||
$this->_em->getClassMetadata(self::CLASS_NAME),
|
||||
//$this->_em->getClassMetadata('Doctrine\Tests\Models\Quote\User'),
|
||||
$this->_em->getClassMetadata('Doctrine\Tests\Models\Quote\Group'),
|
||||
//$this->_em->getClassMetadata('Doctrine\Tests\Models\Quote\Phone'),
|
||||
//$this->_em->getClassMetadata('Doctrine\Tests\Models\Quote\Address'),
|
||||
));
|
||||
} catch(\Exception $e) {
|
||||
$this->fail($e->getMessage());
|
||||
@ -70,42 +72,63 @@ class DDC1843Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$this->assertEquals($e3Id, $e3->id);
|
||||
$this->assertEquals($e4Id, $e4->id);
|
||||
|
||||
return;
|
||||
|
||||
$this->assertEquals('Bar 1', $e1->value);
|
||||
$this->assertEquals('Foo 1', $e2->value);
|
||||
$this->assertEquals('Parent Bar 1', $e1->name);
|
||||
$this->assertEquals('Parent Foo 2', $e2->name);
|
||||
$this->assertEquals('Bar 3', $e3->name);
|
||||
$this->assertEquals('Foo 4', $e4->name);
|
||||
|
||||
$e1->value = 'Bar 2';
|
||||
$e2->value = 'Foo 2';
|
||||
$e1->name = 'Parent Bar 11';
|
||||
$e2->name = 'Parent Foo 22';
|
||||
$e3->name = 'Bar 33';
|
||||
$e4->name = 'Foo 44';
|
||||
|
||||
// Update
|
||||
$this->_em->persist($e1);
|
||||
$this->_em->persist($e2);
|
||||
$this->_em->persist($e3);
|
||||
$this->_em->persist($e4);
|
||||
$this->_em->flush();
|
||||
|
||||
$this->assertEquals('Bar 2', $e1->value);
|
||||
$this->assertEquals('Foo 2', $e2->value);
|
||||
$this->assertEquals('Parent Bar 11', $e1->name);
|
||||
$this->assertEquals('Parent Foo 22', $e2->name);
|
||||
$this->assertEquals('Bar 33', $e3->name);
|
||||
$this->assertEquals('Foo 44', $e4->name);
|
||||
|
||||
$this->assertInstanceOf(self::CLASS_NAME, $e1);
|
||||
$this->assertInstanceOf(self::CLASS_NAME, $e2);
|
||||
$this->assertInstanceOf(self::CLASS_NAME, $e3);
|
||||
$this->assertInstanceOf(self::CLASS_NAME, $e4);
|
||||
|
||||
$this->assertEquals($e1Id, $e1->id);
|
||||
$this->assertEquals($e2Id, $e2->id);
|
||||
$this->assertEquals($e3Id, $e3->id);
|
||||
$this->assertEquals($e4Id, $e4->id);
|
||||
|
||||
$this->assertEquals('Bar 2', $e1->value);
|
||||
$this->assertEquals('Foo 2', $e2->value);
|
||||
$this->assertEquals('Parent Bar 11', $e1->name);
|
||||
$this->assertEquals('Parent Foo 22', $e2->name);
|
||||
$this->assertEquals('Bar 33', $e3->name);
|
||||
$this->assertEquals('Foo 44', $e4->name);
|
||||
|
||||
$this->markTestIncomplete();
|
||||
|
||||
// Delete
|
||||
$this->_em->remove($e1);
|
||||
$this->_em->remove($e2);
|
||||
$this->_em->remove($e3);
|
||||
$this->_em->remove($e4);
|
||||
$this->_em->flush();
|
||||
|
||||
|
||||
$e1 = $this->_em->find(self::CLASS_NAME, $e1Id);
|
||||
$e2 = $this->_em->find(self::CLASS_NAME, $e2Id);
|
||||
$this->assertInstanceOf(self::CLASS_NAME, $e1);
|
||||
$this->assertInstanceOf(self::CLASS_NAME, $e2);
|
||||
$this->assertInstanceOf(self::CLASS_NAME, $e3);
|
||||
$this->assertInstanceOf(self::CLASS_NAME, $e4);
|
||||
|
||||
$this->assertNull($e1);
|
||||
$this->assertNull($e2);
|
||||
$this->assertNull($e3);
|
||||
$this->assertNull($e4);
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user