Commit ddb5a66f authored by romanb's avatar romanb

[2.0][DDC-191][DDC-192] Attempt to fix both.

parent 5730a32d
...@@ -188,7 +188,7 @@ class Table extends AbstractAsset ...@@ -188,7 +188,7 @@ class Table extends AbstractAsset
$columnName = $indexColOptions; $columnName = $indexColOptions;
} }
if (!isset($this->_columns[$columnName])) { if ( ! $this->hasColumn($columnName)) {
throw SchemaException::columnDoesNotExist($columnName); throw SchemaException::columnDoesNotExist($columnName);
} }
} }
...@@ -304,7 +304,7 @@ class Table extends AbstractAsset ...@@ -304,7 +304,7 @@ class Table extends AbstractAsset
$foreignTableName = $foreignTable->getName(); $foreignTableName = $foreignTable->getName();
foreach ($foreignColumnNames AS $columnName) { foreach ($foreignColumnNames AS $columnName) {
if (!$foreignTable->hasColumn($columnName)) { if ( ! $foreignTable->hasColumn($columnName)) {
throw SchemaException::columnDoesNotExist($columnName); throw SchemaException::columnDoesNotExist($columnName);
} }
} }
...@@ -313,7 +313,7 @@ class Table extends AbstractAsset ...@@ -313,7 +313,7 @@ class Table extends AbstractAsset
} }
foreach ($localColumnNames AS $columnName) { foreach ($localColumnNames AS $columnName) {
if (!$this->hasColumn($columnName)) { if ( ! $this->hasColumn($columnName)) {
throw SchemaException::columnDoesNotExist($columnName); throw SchemaException::columnDoesNotExist($columnName);
} }
} }
......
...@@ -384,6 +384,7 @@ class SchemaTool ...@@ -384,6 +384,7 @@ class SchemaTool
$fkOptions = array(); $fkOptions = array();
foreach ($joinColumns as $joinColumn) { foreach ($joinColumns as $joinColumn) {
// Note that this thing might be quoted, i.e. `foo`, [foo], ...
$columnName = $mapping->getQuotedJoinColumnName($joinColumn['name'], $this->_platform); $columnName = $mapping->getQuotedJoinColumnName($joinColumn['name'], $this->_platform);
if (!$class->hasField($class->getFieldName($joinColumn['referencedColumnName']))) { if (!$class->hasField($class->getFieldName($joinColumn['referencedColumnName']))) {
...@@ -397,11 +398,16 @@ class SchemaTool ...@@ -397,11 +398,16 @@ class SchemaTool
$localColumns[] = $columnName; $localColumns[] = $columnName;
$foreignColumns[] = $joinColumn['referencedColumnName']; $foreignColumns[] = $joinColumn['referencedColumnName'];
$theJoinTable->createColumn( if ( ! $theJoinTable->hasColumn($joinColumn['name'])) {
$columnName, $class->getTypeOfColumn($joinColumn['referencedColumnName']), array('notnull' => false) // 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.
$theJoinTable->createColumn(
$columnName, $class->getTypeOfColumn($joinColumn['referencedColumnName']), array('notnull' => false)
);
}
if(isset($joinColumn['unique']) && $joinColumn['unique'] == true) { if (isset($joinColumn['unique']) && $joinColumn['unique'] == true) {
$uniqueConstraints[] = array($columnName); $uniqueConstraints[] = array($columnName);
} }
......
...@@ -183,10 +183,6 @@ class SingleTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase ...@@ -183,10 +183,6 @@ class SingleTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->assertEquals('related to parent!', $related->getData()); $this->assertEquals('related to parent!', $related->getData());
} }
/*public function testPolymorphicQueryWithJoin()
{
}*/
} }
/** /**
......
...@@ -19,7 +19,7 @@ class AllTests ...@@ -19,7 +19,7 @@ class AllTests
{ {
$suite = new \Doctrine\Tests\OrmFunctionalTestSuite('Doctrine Orm Ticket Tests'); $suite = new \Doctrine\Tests\OrmFunctionalTestSuite('Doctrine Orm Ticket Tests');
$tests = glob(__DIR__ . '/Ticket*Test.php'); $tests = glob(__DIR__ . '/*Test.php');
foreach ($tests as $test) { foreach ($tests as $test) {
$info = pathinfo($test); $info = pathinfo($test);
$suite->addTestSuite('Doctrine\Tests\ORM\Functional\Ticket\\' . $info['filename']); $suite->addTestSuite('Doctrine\Tests\ORM\Functional\Ticket\\' . $info['filename']);
......
<?php
namespace Doctrine\Tests\ORM\Functional\Ticket;
require_once __DIR__ . '/../../../TestInit.php';
class DDC192Test extends \Doctrine\Tests\OrmFunctionalTestCase
{
public function testSchemaCreation()
{
$this->_schemaTool->createSchema(array(
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC192User'),
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC192Phonenumber')
));
}
}
/**
* @Entity @Table(name="ddc192_users")
*/
class DDC192User
{
/**
* @Id @Column(name="id", type="integer")
* @GeneratedValue(strategy="AUTO")
*/
public $id;
/**
* @Column(name="name", type="string")
*/
public $name;
}
/**
* @Entity @Table(name="ddc192_phonenumbers")
*/
class DDC192Phonenumber
{
/**
* @Id @Column(name="phone", type="string", length=40)
*/
protected $phone;
/**
* @Id @Column(name="userId", type="integer")
*/
protected $userId;
/**
* @Id
* @ManyToOne(targetEntity="DDC192User")
* @JoinColumn(name="userId", referencedColumnName="id")
*/
protected $User; // Id on this docblock is ignored!
public function setPhone($value) { $this->phone = $value; }
public function getPhone() { return $this->phone; }
public function setUser(User $user)
{
$this->User = $user;
$this->userId = $user->getId(); // TODO: Remove once ManyToOne supports Id annotation
}
public function getUser() { return $this->User; }
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment