1
0
mirror of synced 2024-12-13 06:46:03 +03:00

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

This commit is contained in:
romanb 2009-12-07 16:21:29 +00:00
parent 5730a32d91
commit ddb5a66fd8
5 changed files with 85 additions and 12 deletions

View File

@ -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);
}
}

View File

@ -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);
}

View File

@ -183,10 +183,6 @@ class SingleTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->assertEquals('related to parent!', $related->getData());
}
/*public function testPolymorphicQueryWithJoin()
{
}*/
}
/**

View File

@ -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']);

View File

@ -0,0 +1,71 @@
<?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; }
}