Doctrine 在 Google App Engine 上找不到数据?

Doctrine not finding data on Google App Engine?

当我做一个简单的查询时,比如查找所有用户,它 returns 一个空数组。 $users = $em->getRepository('MyApp\Model\Entity\User')->findAll();

但是,当我使用 PDO 手动连接到我的数据库时,它找到了数据。我正在使用 ArrayCache 方法,以确保它与没有文件系统的 GAE 无关。 GAE 文档说您可以使用 sys_get_temp_dir(),所以我不认为这是我的代理。我不知道为什么 Doctrine 什么都不返回也不抛出任何错误。

这是我的应用的 bootstrap 文件:

<?php

$baseDir = dirname(dirname(__FILE__));

define('TIMEZONE_OFFSET', \MyApp\Library\Date::getMyTimezoneOffset());

use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\AnnotationRegistry;

// globally used cache driver, in production use APC or memcached
$cache = new Doctrine\Common\Cache\ArrayCache;
// standard annotation reader
$annotationReader = new AnnotationReader;
AnnotationReader::addGlobalIgnoredName('dummy');
AnnotationRegistry::registerFile(__DIR__ . "/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php");
AnnotationRegistry::registerFile(__DIR__ . "/Gedmo/Timestampable/Mapping/Driver/Annotation.php");
AnnotationRegistry::registerAutoloadNamespace("\MyApp\Model\Entity", $baseDir);
$cachedAnnotationReader = new Doctrine\Common\Annotations\CachedReader(
    $annotationReader, // use reader
    $cache, // and a cache driver
    $debug = LOCAL
);
// create a driver chain for metadata reading
$driverChain = new Doctrine\ORM\Mapping\Driver\DriverChain();
// load superclass metadata mapping only, into driver chain
// also registers Gedmo annotations.NOTE: you can personalize it
Gedmo\DoctrineExtensions::registerAbstractMappingIntoDriverChainORM(
    $driverChain, // our metadata driver chain, to hook into
    $cachedAnnotationReader // our cached annotation reader
);

// now we want to register our application entities,
// for that we need another metadata driver used for Entity namespace
$annotationDriver = new Doctrine\ORM\Mapping\Driver\AnnotationDriver(
    $cachedAnnotationReader, // our cached annotation reader
    array(ENTITY_PATH) // paths to look in
);
// NOTE: driver for application Entity can be different, Yaml, Xml or whatever
// register annotation driver for our application Entity namespace
$driverChain->addDriver($annotationDriver, 'MyApp\Model\Entity');

// general ORM configuration
$config = new Doctrine\ORM\Configuration;
$config->setProxyDir(sys_get_temp_dir());
$config->setProxyNamespace('Proxy');
$config->setAutoGenerateProxyClasses(Doctrine\Common\Proxy\AbstractProxyFactory::AUTOGENERATE_FILE_NOT_EXISTS); // this can be based on production config.
// register metadata driver
$config->setMetadataDriverImpl($driverChain);
// use our already initialized cache driver
$config->setMetadataCacheImpl($cache);
$config->setQueryCacheImpl($cache);

// create event manager and hook preferred extension listeners
$evm = new Doctrine\Common\EventManager();
// gedmo extension listeners, remove which are not used

// timestampable
$timestampableListener = new Gedmo\Timestampable\TimestampableListener;
$timestampableListener->setAnnotationReader($cachedAnnotationReader);
$evm->addEventSubscriber($timestampableListener);

// mysql set names UTF-8 if required
$evm->addEventSubscriber(new Doctrine\DBAL\Event\Listeners\MysqlSessionInit());

$dbParams = array(
    'driver' => 'pdo_mysql',
    'user' => DB_USER,
    'password' => DB_PASSWORD,
    'dbname' => DB_NAME,
    'host' => DB_HOST,
    'port' => DB_PORT,
    'unix_socket' => DB_UNIX_SOCKET
);

// Finally, create entity manager
$em = Doctrine\ORM\EntityManager::create($dbParams, $config, $evm);

更新

为了清楚起见:

这个returns一个空数组:

$users = $em->getRepository('MyApp\Model\Entity\User')->findAll();
\Doctrine\Common\Util\Debug::dump($users);

而这个 returns 一个包含用户的数组。好迷茫。

$pdo = $em->getConnection();
$users = $pdo->query('SELECT * FROM user');
var_dump($users->fetchAll());

我的问题是我没有在数据库中创建公司,而我的用户实体需要一个公司,因此 Doctrine 使用了 INNER JOIN,因此没有用户。呃.

更新

看到这个问题:Why does Doctrine2 do an INNER JOIN for findAll()?