gpt4 book ai didi

symfony - Doctrine2 存储库中返回实体的类型提示

转载 作者:行者123 更新时间:2023-12-01 05:00:25 25 4
gpt4 key购买 nike

我有 CustomRepository扩展 Doctrine\ORM\EntityRepository 的类.该存储库与许多不同的实体相关联。
存储库中有一个方法可以返回关联的实体。

class CustomRepository extends \Doctrine\ORM\EntityRepository
{
function getEntity() { ... } // returns an instance of associated entity
}

/**
* @ORM\Entity(repositoryClass="CustomRepository")
*/
class EntityClass1 { ... }
/**
* @ORM\Entity(repositoryClass="CustomRepository")
*/
class EntityClass2 { ... }

$repo1 = $entityManager->getRepository('Entity1');
$entity1 = $repo1->getEntity(); // will return an instance of EntityClass1

$repo2 = $entityManager->getRepository('Entity2');
$entity2 = $repo1->getEntity(); // will return an instance of EntityClass2

我使用 Symfony 2 插件,它正确地将继承方法实体返回的类检测为 find .
有没有办法通知插件该方法返回一个关联实体?

最佳答案

你可以使用这样的东西:

/**
* MyEntity repository.
*
* @method MyEntity[] find
*/

关于symfony - Doctrine2 存储库中返回实体的类型提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33436189/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com