-
-
Save doctrinebot/1d8fbf19d0d9ac97cb1d to your computer and use it in GitHub Desktop.
Attachments to Doctrine Jira Issue DDC-251 - https://github.com/doctrine/doctrine2/issues/3232
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Entities { | |
/** | |
* @Entity | |
* @InheritanceType("SINGLE_TABLE") | |
* @DiscriminatorColumn(name="foobar", type="integer") | |
* @DiscriminatorMap({"0" = "Entities\Foo\Collection", "1" = "Collection"}) | |
*/ | |
class Collection | |
{ | |
/** | |
* @Id | |
* @GeneratedValue(strategy="AUTO") | |
* @Column(type="integer") | |
*/ | |
protected $id; | |
/** | |
* @OneToMany(targetEntity="Collection", mappedBy="parent") | |
*/ | |
protected $children; | |
/** | |
* @ManyToOne(targetEntity="Collection") | |
* @JoinColumn(name="parent_id", referencedColumnName="id") | |
*/ | |
protected $parent; | |
/** | |
* @Column(type="string", nullable=true) | |
*/ | |
protected $name; | |
public function getId() | |
{ | |
return $this->id; | |
} | |
public function setParent(Collection $parent) | |
{ | |
$this->parent = $parent; | |
} | |
public function setName($value) | |
{ | |
$this->name = $value; | |
} | |
} | |
} | |
namespace Entities\Foo { | |
/** @Entity */ | |
class Collection extends \Entities\Collection | |
{ | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Welcome to Doctrine 2. | |
* | |
* This is the index file of the sandbox. The first section of this file | |
* demonstrates the bootstrapping and configuration procedure of Doctrine 2. | |
* Below that section you can place your test code and experiment. | |
*/ | |
use Doctrine\Common\ClassLoader, | |
Doctrine\ORM\Configuration, | |
Doctrine\ORM\EntityManager, | |
Doctrine\Common\Cache\ApcCache, | |
Entities\Collection; | |
require '../../lib/Doctrine/Common/ClassLoader.php'; | |
// Set up class loading. You could use different autoloaders, provided by your favorite framework, | |
// if you want to. | |
$doctrineClassLoader = new ClassLoader('Doctrine', realpath(__DIR__ . '/../../lib')); | |
$doctrineClassLoader->register(); | |
$entitiesClassLoader = new ClassLoader('Entities', __DIR__); | |
$entitiesClassLoader->register(); | |
$proxiesClassLoader = new ClassLoader('Proxies', __DIR__); | |
$proxiesClassLoader->register(); | |
// Set up caches | |
$config = new Configuration; | |
$cache = new ApcCache; | |
$config->setMetadataCacheImpl($cache); | |
$config->setQueryCacheImpl($cache); | |
// Proxy configuration | |
$config->setProxyDir(__DIR__ . '/Proxies'); | |
$config->setProxyNamespace('Proxies'); | |
// Database connection information | |
$connectionOptions = array( | |
'driver' => 'pdo_sqlite', | |
'path' => 'database.sqlite' | |
); | |
// Create EntityManager | |
$em = EntityManager::create($connectionOptions, $config); | |
## PUT YOUR TEST CODE BELOW | |
$collection1 = new Collection; | |
$collection1->setName("Collection number one"); | |
$em->persist($collection1); | |
$collection2 = new Collection; | |
$collection2->setName("Collection number one"); | |
$collection2->setParent($collection1); | |
$em->persist($collection2); | |
$em->flush(); | |
$em->clear(); | |
$dql = "SELECT c FROM Entities\Collection c WHERE c.id = :id"; | |
$q = $em->createQuery($dql); | |
$q->setParameter("id", 2); | |
$collection1 = $q->getSingleResult(\Doctrine\ORM\Query::HYDRATE_OBJECT); | |
$em->flush(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment