I have CustomRepository
class which extends Doctrine\ORM\EntityRepository
. This repository is assosiated with many different entities.
There is a method in the repository which returns an associated entity.
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
I use Symfony 2 plugin, which correctly detects the class of returned by inherited methods entities as find
.
Is there a way to inform the plugin that the method returns an assosiated entity?
You can use something like this:
/**
* MyEntity repository.
*
* @method MyEntity[] find
*/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With