Merge branch 'master' of github.com:doctrine/doctrine2
This commit is contained in:
commit
438de30aa3
@ -1,3 +1,10 @@
|
||||
# Update from 2.0-BETA2 to 2.0-BETA3
|
||||
|
||||
## Default Allocation Size for Sequences
|
||||
|
||||
The default allocation size for sequences has been changed from 10 to 1. This step was made
|
||||
to not cause confusion with users and also because it is partly some kind of premature optimization.
|
||||
|
||||
# Update from 2.0-BETA1 to 2.0-BETA2
|
||||
|
||||
There are no backwards incompatible changes in this release.
|
||||
|
@ -1,7 +1,5 @@
|
||||
<?php
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
@ -34,9 +32,9 @@ use Doctrine\Common\Cache\ArrayCache,
|
||||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
||||
* @link www.doctrine-project.org
|
||||
* @since 2.0
|
||||
* @version $Revision$
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
* @author Jonathan Wage <jonwage@gmail.com>
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
*/
|
||||
class DatabaseDriver implements Driver
|
||||
{
|
||||
@ -73,6 +71,11 @@ class DatabaseDriver implements Driver
|
||||
$foreignKeys = array();
|
||||
}
|
||||
|
||||
$allForeignKeyColumns = array();
|
||||
foreach ($foreignKeys AS $foreignKey) {
|
||||
$allForeignKeyColumns = array_merge($allForeignKeyColumns, $foreignKey->getLocalColumns());
|
||||
}
|
||||
|
||||
$indexes = $this->_sm->listTableIndexes($tableName);
|
||||
|
||||
$ids = array();
|
||||
@ -81,6 +84,8 @@ class DatabaseDriver implements Driver
|
||||
$fieldMapping = array();
|
||||
if (isset($indexes['primary']) && in_array($column->getName(), $indexes['primary']->getColumns())) {
|
||||
$fieldMapping['id'] = true;
|
||||
} else if (in_array($column->getName(), $allForeignKeyColumns)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$fieldMapping['fieldName'] = Inflector::camelize(strtolower($column->getName()));
|
||||
@ -123,7 +128,7 @@ class DatabaseDriver implements Driver
|
||||
$fkCols = $foreignKey->getForeignColumns();
|
||||
|
||||
$associationMapping = array();
|
||||
$associationMapping['fieldName'] = Inflector::camelize(str_ireplace('_id', '', $localColumn));
|
||||
$associationMapping['fieldName'] = Inflector::camelize(str_replace('_id', '', strtolower($localColumn)));
|
||||
$associationMapping['targetEntity'] = Inflector::classify($foreignKey->getForeignTableName());
|
||||
|
||||
for ($i = 0; $i < count($cols); $i++) {
|
||||
@ -146,16 +151,19 @@ class DatabaseDriver implements Driver
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* Return all the class names supported by this driver.
|
||||
*
|
||||
* IMPORTANT: This method must return an array of table names because we need
|
||||
* to know the table name after we inflect it to create the entity class name.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAllClassNames()
|
||||
{
|
||||
$classes = array();
|
||||
|
||||
foreach ($this->_sm->listTables() as $table) {
|
||||
// This method must return an array of table names because we need
|
||||
// to know the table name after we inflect it to create the entity class name.
|
||||
$classes[] = $table->getName();
|
||||
foreach ($this->_sm->listTableNames() as $tableName) {
|
||||
$classes[] = $tableName;
|
||||
}
|
||||
|
||||
return $classes;
|
||||
|
@ -119,7 +119,7 @@ final class JoinTable extends Annotation {
|
||||
}
|
||||
final class SequenceGenerator extends Annotation {
|
||||
public $sequenceName;
|
||||
public $allocationSize = 10;
|
||||
public $allocationSize = 1;
|
||||
public $initialValue = 1;
|
||||
}
|
||||
final class ChangeTrackingPolicy extends Annotation {}
|
||||
|
@ -106,21 +106,25 @@ class XmlDriver extends AbstractFileDriver
|
||||
|
||||
// Evaluate <indexes...>
|
||||
if (isset($xmlRoot->indexes)) {
|
||||
$metadata->table['indexes'] = array();
|
||||
foreach ($xmlRoot->indexes->index as $index) {
|
||||
if (is_string($index['columns'])) {
|
||||
$columns = explode(',', $index['columns']);
|
||||
} else {
|
||||
$columns = $index['columns'];
|
||||
}
|
||||
$columns = explode(',', (string)$index['columns']);
|
||||
|
||||
$metadata->table['indexes'][$index['name']] = array(
|
||||
'columns' => $columns
|
||||
);
|
||||
if (isset($index['name'])) {
|
||||
$metadata->table['indexes'][(string)$index['name']] = array(
|
||||
'columns' => $columns
|
||||
);
|
||||
} else {
|
||||
$metadata->table['indexes'][] = array(
|
||||
'columns' => $columns
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Evaluate <unique-constraints..>
|
||||
if (isset($xmlRoot->{'unique-constraints'})) {
|
||||
$metadata->table['uniqueConstraints'] = array();
|
||||
foreach ($xmlRoot->{'unique-constraints'}->{'unique-constraint'} as $unique) {
|
||||
$columns = explode(',', (string)$unique['columns']);
|
||||
|
||||
|
@ -14,15 +14,15 @@ class DateTimeModel
|
||||
*/
|
||||
public $id;
|
||||
/**
|
||||
* @Column(name="col_datetime", type="datetime")
|
||||
* @Column(name="col_datetime", type="datetime", nullable=true)
|
||||
*/
|
||||
public $datetime;
|
||||
/**
|
||||
* @Column(name="col_date", type="date")
|
||||
* @Column(name="col_date", type="date", nullable=true)
|
||||
*/
|
||||
public $date;
|
||||
/**
|
||||
* @Column(name="col_time", type="time")
|
||||
* @Column(name="col_time", type="time", nullable=true)
|
||||
*/
|
||||
public $time;
|
||||
}
|
@ -21,7 +21,7 @@ class DatabaseDriverTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$this->_sm = $this->_em->getConnection()->getSchemaManager();
|
||||
}
|
||||
|
||||
public function testCreateSimpleYamlFromDatabase()
|
||||
public function testLoadMetadataFromDatabase()
|
||||
{
|
||||
if (!$this->_em->getConnection()->getDatabasePlatform()->supportsForeignKeyConstraints()) {
|
||||
$this->markTestSkipped('Platform does not support foreign keys.');
|
||||
@ -34,7 +34,10 @@ class DatabaseDriverTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
|
||||
$this->_sm->dropAndCreateTable($table);
|
||||
|
||||
$metadata = $this->extractClassMetadata("DbdriverFoo");
|
||||
$metadatas = $this->extractClassMetadata(array("DbdriverFoo"));
|
||||
|
||||
$this->assertArrayHasKey('dbdriver_foo', $metadatas);
|
||||
$metadata = $metadatas['dbdriver_foo'];
|
||||
|
||||
$this->assertArrayHasKey('id', $metadata->fieldMappings);
|
||||
$this->assertEquals('id', $metadata->fieldMappings['id']['fieldName']);
|
||||
@ -49,7 +52,7 @@ class DatabaseDriverTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$this->assertTrue($metadata->fieldMappings['bar']['nullable']);
|
||||
}
|
||||
|
||||
public function testCreateYamlWithForeignKeyFromDatabase()
|
||||
public function testLoadMetadataWithForeignKeyFromDatabase()
|
||||
{
|
||||
if (!$this->_em->getConnection()->getDatabasePlatform()->supportsForeignKeyConstraints()) {
|
||||
$this->markTestSkipped('Platform does not support foreign keys.');
|
||||
@ -69,15 +72,18 @@ class DatabaseDriverTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
|
||||
$this->_sm->dropAndCreateTable($tableA);
|
||||
|
||||
$metadata = $this->extractClassMetadata("DbdriverBaz");
|
||||
$metadatas = $this->extractClassMetadata(array("DbdriverBar", "DbdriverBaz"));
|
||||
|
||||
$this->assertArrayNotHasKey('bar', $metadata->fieldMappings);
|
||||
$this->assertArrayHasKey('id', $metadata->fieldMappings);
|
||||
$this->assertArrayHasKey('dbdriver_baz', $metadatas);
|
||||
$bazMetadata = $metadatas['dbdriver_baz'];
|
||||
|
||||
$metadata->associationMappings = \array_change_key_case($metadata->associationMappings, \CASE_LOWER);
|
||||
$this->assertArrayNotHasKey('barId', $bazMetadata->fieldMappings, "The foreign Key field should not be inflected as 'barId' field, its an association.");
|
||||
$this->assertArrayHasKey('id', $bazMetadata->fieldMappings);
|
||||
|
||||
$this->assertArrayHasKey('bar', $metadata->associationMappings);
|
||||
$this->assertType('Doctrine\ORM\Mapping\OneToOneMapping', $metadata->associationMappings['bar']);
|
||||
$bazMetadata->associationMappings = \array_change_key_case($bazMetadata->associationMappings, \CASE_LOWER);
|
||||
|
||||
$this->assertArrayHasKey('bar', $bazMetadata->associationMappings);
|
||||
$this->assertType('Doctrine\ORM\Mapping\OneToOneMapping', $bazMetadata->associationMappings['bar']);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -85,18 +91,24 @@ class DatabaseDriverTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
* @param string $className
|
||||
* @return ClassMetadata
|
||||
*/
|
||||
protected function extractClassMetadata($className)
|
||||
protected function extractClassMetadata(array $classNames)
|
||||
{
|
||||
$classNames = array_map('strtolower', $classNames);
|
||||
$metadatas = array();
|
||||
|
||||
$driver = new \Doctrine\ORM\Mapping\Driver\DatabaseDriver($this->_sm);
|
||||
foreach ($driver->getAllClassNames() as $dbTableName) {
|
||||
if (strtolower(Inflector::classify($dbTableName)) != strtolower($className)) {
|
||||
if (!in_array(strtolower(Inflector::classify($dbTableName)), $classNames)) {
|
||||
continue;
|
||||
}
|
||||
$class = new ClassMetadataInfo($dbTableName);
|
||||
$driver->loadMetadataForClass($dbTableName, $class);
|
||||
return $class;
|
||||
$metadatas[strtolower($dbTableName)] = $class;
|
||||
}
|
||||
|
||||
$this->fail("No class matching the name '".$className."' was found!");
|
||||
if (count($metadatas) != count($classNames)) {
|
||||
$this->fail("Have not found all classes matching the names '" . implode(", ", $classNames) . "' only tables " . implode(", ", array_keys($metadatas)));
|
||||
}
|
||||
return $metadatas;
|
||||
}
|
||||
}
|
||||
|
@ -91,4 +91,49 @@ class TypeTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
|
||||
$this->assertType('stdClass', $serialize->object);
|
||||
}
|
||||
|
||||
public function testDate()
|
||||
{
|
||||
$dateTime = new DateTimeModel();
|
||||
$dateTime->date = new \DateTime('2009-10-01', new \DateTimeZone('Europe/Berlin'));
|
||||
|
||||
$this->_em->persist($dateTime);
|
||||
$this->_em->flush();
|
||||
$this->_em->clear();
|
||||
|
||||
$dateTimeDb = $this->_em->find('Doctrine\Tests\Models\Generic\DateTimeModel', $dateTime->id);
|
||||
|
||||
$this->assertType('DateTime', $dateTimeDb->date);
|
||||
$this->assertEquals('2009-10-01', $dateTimeDb->date->format('Y-m-d'));
|
||||
}
|
||||
|
||||
public function testDateTime()
|
||||
{
|
||||
$dateTime = new DateTimeModel();
|
||||
$dateTime->datetime = new \DateTime('2009-10-02 20:10:52', new \DateTimeZone('Europe/Berlin'));
|
||||
|
||||
$this->_em->persist($dateTime);
|
||||
$this->_em->flush();
|
||||
$this->_em->clear();
|
||||
|
||||
$dateTimeDb = $this->_em->find('Doctrine\Tests\Models\Generic\DateTimeModel', $dateTime->id);
|
||||
|
||||
$this->assertType('DateTime', $dateTime->datetime);
|
||||
$this->assertEquals('2009-10-02 20:10:52', $dateTimeDb->datetime->format('Y-m-d H:i:s'));
|
||||
}
|
||||
|
||||
public function testTime()
|
||||
{
|
||||
$dateTime = new DateTimeModel();
|
||||
$dateTime->time = new \DateTime('2010-01-01 19:27:20');
|
||||
|
||||
$this->_em->persist($dateTime);
|
||||
$this->_em->flush();
|
||||
$this->_em->clear();
|
||||
|
||||
$dateTimeDb = $this->_em->find('Doctrine\Tests\Models\Generic\DateTimeModel', $dateTime->id);
|
||||
|
||||
$this->assertType('DateTime', $dateTime->time);
|
||||
$this->assertEquals('19:27:20', $dateTime->time->format('H:i:s'));
|
||||
}
|
||||
}
|
@ -36,6 +36,21 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase
|
||||
return $class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testEntityTableNameAndInheritance
|
||||
* @param ClassMetadata $class
|
||||
*/
|
||||
public function testEntityIndexes($class)
|
||||
{
|
||||
$this->assertArrayHasKey('indexes', $class->table, 'ClassMetadata should have indexes key in table property.');
|
||||
$this->assertEquals(array(
|
||||
'name_idx' => array('columns' => array('name')),
|
||||
0 => array('columns' => array('user_email'))
|
||||
), $class->table['indexes']);
|
||||
|
||||
return $class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testEntityTableNameAndInheritance
|
||||
* @param ClassMetadata $class
|
||||
@ -240,7 +255,11 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase
|
||||
/**
|
||||
* @Entity
|
||||
* @HasLifecycleCallbacks
|
||||
* @Table(name="cms_users", uniqueConstraints={@UniqueConstraint(name="search_idx", columns={"name", "user_email"})})
|
||||
* @Table(
|
||||
* name="cms_users",
|
||||
* uniqueConstraints={@UniqueConstraint(name="search_idx", columns={"name", "user_email"})},
|
||||
* indexes={@Index(name="name_idx", columns={"name"}), @Index(name="0", columns={"user_email"})}
|
||||
* )
|
||||
*/
|
||||
class User
|
||||
{
|
||||
@ -411,6 +430,9 @@ class User
|
||||
$metadata->table['uniqueConstraints'] = array(
|
||||
'search_idx' => array('columns' => array('name', 'user_email')),
|
||||
);
|
||||
$metadata->table['indexes'] = array(
|
||||
'name_idx' => array('columns' => array('name')), 0 => array('columns' => array('user_email'))
|
||||
);
|
||||
$metadata->setSequenceGeneratorDefinition(array(
|
||||
'sequenceName' => 'tablename_seq',
|
||||
'allocationSize' => 100,
|
||||
|
@ -106,6 +106,9 @@ $metadata->mapManyToMany(array(
|
||||
$metadata->table['uniqueConstraints'] = array(
|
||||
'search_idx' => array('columns' => array('name', 'user_email')),
|
||||
);
|
||||
$metadata->table['indexes'] = array(
|
||||
'name_idx' => array('columns' => array('name')), 0 => array('columns' => array('user_email'))
|
||||
);
|
||||
$metadata->setSequenceGeneratorDefinition(array(
|
||||
'sequenceName' => 'tablename_seq',
|
||||
'allocationSize' => 100,
|
||||
|
@ -7,6 +7,11 @@
|
||||
|
||||
<entity name="Doctrine\Tests\ORM\Mapping\User" table="cms_users">
|
||||
|
||||
<indexes>
|
||||
<index name="name_idx" columns="name"/>
|
||||
<index columns="user_email"/>
|
||||
</indexes>
|
||||
|
||||
<unique-constraints>
|
||||
<unique-constraint columns="name,user_email" name="search_idx" />
|
||||
</unique-constraints>
|
||||
|
@ -58,4 +58,9 @@ Doctrine\Tests\ORM\Mapping\User:
|
||||
postPersist: [ doStuffOnPostPersist ]
|
||||
uniqueConstraints:
|
||||
search_idx:
|
||||
columns: name,user_email
|
||||
columns: name,user_email
|
||||
indexes:
|
||||
name_idx:
|
||||
columns: name
|
||||
0:
|
||||
columns: user_email
|
Loading…
Reference in New Issue
Block a user