2

我在我的实体中建立了一对多的关系。当尝试获取相关行集时,它会带来空结果,当尝试从子实体中查找父行时,它会抛出Entity was not found异常

这是我的 initDoctrine

$classLoader = new \Doctrine\Common\ClassLoader(
                        'Doctrine',
                        APPLICATION_PATH . '/../library/'
        );
        $classLoader->register();
        $config = new \Doctrine\ORM\Configuration();
        $cache = new \Doctrine\Common\Cache\ArrayCache;
        $config->setMetadataCacheImpl($cache);
        $config->setQueryCacheImpl($cache);
        $driver = $config->newDefaultAnnotationDriver(array(APPLICATION_PATH . '/models'));
        $config->setMetadataDriverImpl($driver);
        $config->setProxyDir(APPLICATION_PATH . '/../bin/tmp/Proxies');
        $config->setProxyNamespace('App\Proxies');
        $config->setAutoGenerateProxyClasses(true);
        $connectionSettings = $this->getOption('doctrine');

这是我的关系

/**
* @var array $userFacebooks
* 
* @OneToMany(targetEntity="Application_Model_UserFacebook", mappedBy="user")
*/
protected $userFacebooks;

和父母之一

/**
* @ManyToOne(targetEntity="Application_Model_User", inversedBy="userFacebooks")
* @JoinColumn(name="user_id", referencedColumnName="id") 
*/
protected $user;
4

1 回答 1

0

映射看起来不错。检查您的所有实体类是否都带有以下注释:

/**
 * @entity
 */
class Entity_Name { ... }
于 2012-10-01T07:24:39.973 回答