php - 使用 getRepository 找不到特定的自定义存储库,但其他的工作正常
问题描述
在我的应用程序中,我有几个自定义存储库,它们与各自的实体类和 orm.yml 文件映射。
它们都以相同的方式定义,当然它们的名称和成员也不同。
然而,当我尝试获取自定义存储库时,仅针对特定存储库,我得到了存储库的超类,而不是正确的存储库。
$a = $this->em->getRepository('MyAppCommonBundle:Activity'); //doesn't work
$b = $this->em->getRepository('MyAppCommonBundle:Activity:User'); //works
$c= $this->em->getRepository('MyAppCommonBundle:ActivityStatus'); //works
MyAppCommonBundle 定义为:MyAppCommonBundle' => 'MyApp\CommonBundle\Entity
$a 返回错误的超类 Doctrine\ORM\EntityRepository 而 $b 返回正确的 MyApp\CommonBundle\Repository\UserRepository 并且 $c 是 MyApp\CommonBundle\Repository\ActivityStatus
所有实体都在同一个文件夹 MyApp\CommonBundle\Entity 中。所有存储库也位于同一位置 MyApp\CommonBundle\Repository。
活动.orm.yml:
MyApp\CommonBundle\Entity\Activity:
type: entity
table: activity
repositoryClass: MyApp\CommonBundle\Repository\ActivityRepository
indexes:
例如 User.orm.yml:
MyApp\CommonBundle\Entity\User:
type: entity
table: user
repositoryClass: MyApp\CommonBundle\Repository\UserRepository
活动资料库:
<?php
namespace MyApp\CommonBundle\Repository;
use Doctrine\ORM\EntityRepository;
class ActivityRepository extends EntityRepository
{
用户存储库:
<?php
namespace MyApp\CommonBundle\Repository;
use Doctrine\ORM\EntityRepository;
class UserRepository extends EntityRepository
...
如上所述,找到了 User 和其他存储库,Activity 不是...
我尝试清除缓存,重建没有效果的实体。显然试图寻找错别字等,但看起来不错。
任何想法?谢谢
解决方案
Cerad,没有相关的 ORM 注释。活动实体:
<?php
namespace MyApp\CommonBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Activity
*
* @ORM\Table(name="activity"...)
* @ORM\Entity
*/
class Activity
{...
用户实体:
<?php
namespace MyApp\CommonBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* User
*
* @ORM\Table(name="user"...)
* @ORM\Entity
*/
class User
{
....
根本没有 orm.xml 文件。弗兰克,是的,存储库类名与其文件名相同。
推荐阅读
- ios - Firebase 存储为 url 返回 nil
- c# - 如何在 Swagger UI 中发送字符串数组作为参数进行测试?
- php - 无法更新在 PHP 中回显的元素的 href?
- android - 应用所有权转让 - 用户视角
- python - PYMC3混合模型:帮助理解多变量模型
- dialogflow-es - 来自数据库的 Dialogflow 插槽验证
- image-processing - 理解颜色如何应用于每个像素的问题
- xamarin - 在 Xamarin Forms 中关闭浏览器而无需用户交互
- c# - Asp.Net Core MVC Web 应用程序中的单元测试
- android - Kotlin GoogleMaps ClusterManager 返回的集群项目大小小于最初传递给它的项目大小