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
$columnName = $indexColOptions;
}
if (!isset($this->_columns[$columnName])) {
if ( ! $this->hasColumn($columnName)) {
throw SchemaException::columnDoesNotExist($columnName);
}
}
......@@ -304,7 +304,7 @@ class Table extends AbstractAsset
$foreignTableName = $foreignTable->getName();
foreach ($foreignColumnNames AS $columnName) {
if (!$foreignTable->hasColumn($columnName)) {
if ( ! $foreignTable->hasColumn($columnName)) {
throw SchemaException::columnDoesNotExist($columnName);
}
}
......@@ -313,7 +313,7 @@ class Table extends AbstractAsset
}
foreach ($localColumnNames AS $columnName) {
if (!$this->hasColumn($columnName)) {
if ( ! $this->hasColumn($columnName)) {
throw SchemaException::columnDoesNotExist($columnName);
}
}
......
......@@ -384,6 +384,7 @@ class SchemaTool
$fkOptions = array();
foreach ($joinColumns as $joinColumn) {
// Note that this thing might be quoted, i.e. `foo`, [foo], ...
$columnName = $mapping->getQuotedJoinColumnName($joinColumn['name'], $this->_platform);
if (!$class->hasField($class->getFieldName($joinColumn['referencedColumnName']))) {
......@@ -397,11 +398,16 @@ class SchemaTool
$localColumns[] = $columnName;
$foreignColumns[] = $joinColumn['referencedColumnName'];
$theJoinTable->createColumn(
$columnName, $class->getTypeOfColumn($joinColumn['referencedColumnName']), array('notnull' => false)
);
if ( ! $theJoinTable->hasColumn($joinColumn['name'])) {
// 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);
}
......
......@@ -183,10 +183,6 @@ class SingleTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->assertEquals('related to parent!', $related->getData());
}
/*public function testPolymorphicQueryWithJoin()
{
}*/
}
/**
......
......@@ -19,7 +19,7 @@ class AllTests
{
$suite = new \Doctrine\Tests\OrmFunctionalTestSuite('Doctrine Orm Ticket Tests');
$tests = glob(__DIR__ . '/Ticket*Test.php');
$tests = glob(__DIR__ . '/*Test.php');
foreach ($tests as $test) {
$info = pathinfo($test);
$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