1
0
Fork 0
mirror of synced 2025-04-01 12:26:11 +03:00

Refactored DDC-671 model to become a first-class modelset, we dont have one with mapped superclass yet.

This commit is contained in:
Benjamin Eberlei 2010-09-21 23:53:26 +02:00
parent 7dc8ef1db9
commit 39f732ab91
10 changed files with 159 additions and 100 deletions

View file

@ -0,0 +1,49 @@
<?php
/*
* 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
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\Tests\Models\DirectoryTree;
/**
* @MappedSuperclass
*/
abstract class AbstractContentItem
{
/**
* @Id @Column(type="integer") @GeneratedValue
*/
private $id;
/**
* @ManyToOne(targetEntity="Directory")
*/
protected $parentDirectory;
/** @column(type="string") */
protected $name;
public function __get($name)
{
return $this->$name;
}
public function __set($name, $value)
{
$this->$name = $value;
}
}

View file

@ -0,0 +1,39 @@
<?php
/*
* 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
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\Tests\Models\DirectoryTree;
/**
* @Entity
*/
class Directory extends AbstractContentItem
{
/**
* @OneToMany(targetEntity="Directory", mappedBy="parent")
*/
protected $subDirectories;
/**
* @OneToMany(targetEntity="File", mappedBy="parent")
*/
protected $containedFiles;
/**
* @Column(type="string")
*/
protected $path;
}

View file

@ -0,0 +1,30 @@
<?php
/*
* 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
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\Tests\Models\DirectoryTree;
/**
* @Entity
*/
class File extends AbstractContentItem
{
/** @Column(type="string") */
protected $extension = "html";
}

View file

@ -459,48 +459,3 @@ class User
));
}
}
abstract class AbstractContentItem
{
/**
* Doctrine2 entity id
* @var integer
*/
private $id;
/**
* The parent directory
* @var Directory
*/
protected $parentDirectory;
/**
* Filename (without extension) or directory name
* @var string
*/
protected $name;
}
class Directory extends AbstractContentItem
{
protected $subDirectories;
/**
* This is a collection of files that are contained in this Directory. Files, for example, could be Pages, but even other files
* like media files (css, images etc) are possible.
*
* @var \Doctrine\Common\Collections\Collection
* @access protected
*/
protected $containedFiles;
/**
* @var string
*/
protected $url;
}
class Page extends AbstractContentItem
{
protected $extension = "html";
}

View file

@ -117,25 +117,20 @@ class AnnotationDriverTest extends AbstractMappingDriverTest
*/
public function testJoinTablesWithMappedSuperclassForAnnotationDriver()
{
$annotationDriver = $this->_loadDriver();
$annotationDriver->addPaths(array(__DIR__ . '/../../Models/DirectoryTree/'));
$em = $this->_getTestEntityManager();
$em->getConfiguration()->setMetadataDriverImpl($this->_loadDriver());
$em->getConfiguration()->setMetadataDriverImpl($annotationDriver);
$factory = new \Doctrine\ORM\Mapping\ClassMetadataFactory($em);
$classPage = $em->getClassMetadata('Doctrine\Tests\ORM\Mapping\Page');
$this->assertEquals('Doctrine\Tests\ORM\Mapping\Page', $classPage->associationMappings['parentDirectory']['sourceEntity']);
$classDirectory = $em->getClassMetadata('Doctrine\Tests\ORM\Mapping\Directory');
$this->assertEquals('Doctrine\Tests\ORM\Mapping\Directory', $classDirectory->associationMappings['parentDirectory']['sourceEntity']);
$classPage = new ClassMetadata('Doctrine\Tests\Models\DirectoryTree\File');
$classPage = $factory->getMetadataFor('Doctrine\Tests\Models\DirectoryTree\File');
$this->assertEquals('Doctrine\Tests\Models\DirectoryTree\File', $classPage->associationMappings['parentDirectory']['sourceEntity']);
$dql = "SELECT f FROM Doctrine\Tests\ORM\Mapping\Page f JOIN f.parentDirectory d " .
"WHERE (d.url = :url) AND (f.extension = :extension)";
$query = $em->createQuery($dql)
->setParameter('url', "test")
->setParameter('extension', "extension");
$this->assertEquals(
'SELECT c0_.id AS id0, c0_.extension AS extension1, c0_.parent_directory_id AS parent_directory_id2 FROM core_content_pages c0_ INNER JOIN core_content_directories c1_ ON c0_.parent_directory_id = c1_.id WHERE (c1_.url = ?) AND (c0_.extension = ?)',
$query->getSql()
);
$classDirectory = new ClassMetadata('Doctrine\Tests\Models\DirectoryTree\Directory');
$classDirectory = $factory->getMetadataFor('Doctrine\Tests\Models\DirectoryTree\Directory');
$this->assertEquals('Doctrine\Tests\Models\DirectoryTree\Directory', $classDirectory->associationMappings['parentDirectory']['sourceEntity']);
}
}

View file

@ -26,25 +26,20 @@ class YamlMappingDriverTest extends AbstractMappingDriverTest
*/
public function testJoinTablesWithMappedSuperclassForYamlDriver()
{
$yamlDriver = $this->_loadDriver();
$yamlDriver->addPaths(array(__DIR__ . DIRECTORY_SEPARATOR . 'yaml'));
$em = $this->_getTestEntityManager();
$em->getConfiguration()->setMetadataDriverImpl($this->_loadDriver());
$em->getConfiguration()->setMetadataDriverImpl($yamlDriver);
$factory = new \Doctrine\ORM\Mapping\ClassMetadataFactory($em);
$classPage = $em->getClassMetadata('Doctrine\Tests\ORM\Mapping\Page');
$this->assertEquals('Doctrine\Tests\ORM\Mapping\Page', $classPage->associationMappings['parentDirectory']['sourceEntity']);
$classDirectory = $em->getClassMetadata('Doctrine\Tests\ORM\Mapping\Directory');
$this->assertEquals('Doctrine\Tests\ORM\Mapping\Directory', $classDirectory->associationMappings['parentDirectory']['sourceEntity']);
$classPage = new ClassMetadata('Doctrine\Tests\Models\DirectoryTree\File');
$classPage = $factory->getMetadataFor('Doctrine\Tests\Models\DirectoryTree\File');
$this->assertEquals('Doctrine\Tests\Models\DirectoryTree\File', $classPage->associationMappings['parentDirectory']['sourceEntity']);
$dql = "SELECT f FROM Doctrine\Tests\ORM\Mapping\Page f JOIN f.parentDirectory d " .
"WHERE (d.url = :url) AND (f.extension = :extension)";
$query = $em->createQuery($dql)
->setParameter('url', "test")
->setParameter('extension', "extension");
$this->assertEquals(
'SELECT c0_.id AS id0, c0_.extension AS extension1, c0_.parent_directory_id AS parent_directory_id2 FROM core_content_pages c0_ INNER JOIN core_content_directories c1_ ON c0_.parent_directory_id = c1_.id WHERE (c1_.url = ?) AND (c0_.extension = ?)',
$query->getSql()
);
$classDirectory = new ClassMetadata('Doctrine\Tests\Models\DirectoryTree\Directory');
$classDirectory = $factory->getMetadataFor('Doctrine\Tests\Models\DirectoryTree\Directory');
$this->assertEquals('Doctrine\Tests\Models\DirectoryTree\Directory', $classDirectory->associationMappings['parentDirectory']['sourceEntity']);
}
}

View file

@ -0,0 +1,14 @@
Doctrine\Tests\Models\DirectoryTree\AbstractContentItem:
type: mappedSuperclass
id:
id:
type: integer
unsigned: true
generator:
strategy: AUTO
fields:
name:
type: string
manyToOne:
parentDirectory:
targetEntity: Doctrine\Tests\Models\DirectoryTree\Directory

View file

@ -1,17 +1,16 @@
Doctrine\Tests\ORM\Mapping\Directory:
Doctrine\Tests\Models\DirectoryTree\Directory:
type: entity
table: core_content_directories
fields:
url:
path:
type: string
length: 255
oneToMany:
subDirectories:
targetEntity: Doctrine\Tests\ORM\Mapping\Directory
targetEntity: Doctrine\Tests\Models\DirectoryTree\Directory
mappedBy: parentDirectory
cascade:
[ all ]
containedFiles:
targetEntity: Doctrine\Tests\ORM\Mapping\Page
targetEntity: Doctrine\Tests\Models\DirectoryTree\File
mappedBy: parentDirectory
cascade: [ remove ]

View file

@ -1,6 +1,5 @@
Doctrine\Tests\ORM\Mapping\Page:
Doctrine\Tests\Models\DirectoryTree\File:
type: entity
table: core_content_pages
fields:
extension:
type: string

View file

@ -1,16 +0,0 @@
Doctrine\Tests\ORM\Mapping\AbstractContentItem:
type: mappedSuperclass
id:
id:
type: integer
unsigned: true
generator:
strategy: AUTO
fields:
# FilesystemIdentifier
manyToOne:
parentDirectory:
targetEntity: Doctrine\Tests\ORM\Mapping\Directory
joinColumn:
name: parent_directory_id
referencedColumnName: id