Skip to content

Instantly share code, notes, and snippets.

@MitMaro
Created May 6, 2011 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MitMaro/959013 to your computer and use it in GitHub Desktop.
Save MitMaro/959013 to your computer and use it in GitHub Desktop.
Doctrine 2 Remove Bug
<?php
require_once 'library/Doctrine/Common/ClassLoader.php';
$classLoader = new Doctrine\Common\ClassLoader('Doctrine', 'library/');
$classLoader->register();
// Set up caches
$config = new Doctrine\ORM\Configuration;
$cache = new Doctrine\Common\Cache\ArrayCache;
$config->setMetadataCacheImpl($cache);
$config->setQueryCacheImpl($cache);
$config->setMetadataDriverImpl($config->newDefaultAnnotationDriver());
// Proxy configuration
$config->setProxyDir(__DIR__);
$config->setProxyNamespace('Proxies');
$config->setMetadataCacheImpl($cache);
// Create EntityManager
$em = Doctrine\ORM\EntityManager::create(array('driver' => 'pdo_sqlite', 'memory' => true), $config);
// setup data
$em->getConnection()->query('CREATE TABLE Bar (
id INTEGER NOT NULL,
foo_id INTEGER NOT NULL,
PRIMARY KEY (id)
)');
$em->getConnection()->query('CREATE TABLE Foo (
id INTEGER NOT NULL,
PRIMARY KEY (id)
)');
$em->getConnection()->query('INSERT INTO Foo (id) VALUES (1)');
$em->getConnection()->query('INSERT INTO Bar (id, foo_id) VALUES (20, 1)');
$qb = $em
->getRepository('Bar')
->createQueryBuilder('bar1')
->select('bar1, foo1, bar2')
->join('bar1.foo', 'foo1')
->join('foo1.bar', 'bar2')
;
$qb->getQuery()->getResult();
$bar = $em->getRepository('Bar')->findOneBy(array('id' => 20));
$em->transactional(function($em) use ($bar) {
$em->remove($bar);
$em->flush();
});
class Base {
public function __get($name) {
return $this->$name;
}
public function __set($name, $value) {
$this->$name = $value;
}
}
/** @Entity */
class Bar extends Base {
/**
* @Id @GeneratedValue @Column(type="integer")
*/
protected $id;
/** @ManyToOne(targetEntity="Foo", inversedBy="bar") */
protected $foo;
}
/** @Entity */
class Foo extends Base {
/**
* @Id @GeneratedValue @Column(type="integer")
*/
protected $id;
/** @OneToMany(targetEntity="Bar", mappedBy="foo") */
protected $bar;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment