is it possible to have two repositories for the same entity ?
I try something like that, but it does not work..
class PackageRepository extends EntityRepository
{
public function __construct($em, Mapping\ClassMetadata $class)
{
$cmf = $em->getMetadataFactory();
$class = $cmf->getMetadataFor('Product');
parent::__construct($em, $class);
}
}
Any ideas ?
First of all, why would you want to do that?
Second, to answer your question. You can have as many repositories working with same entities as you like, they are just simple classes after all.
But you can link only one class with the entity class using the @Repository annotation (or YAML, or XML, whatever). All the mapping data is stored in the EntityManager. EntityManager will know only one repository class is linked with the entity class, if you try to get it with $entity->getReposiotry()
or similar it will return only the linked class.
But nothing can stop you from creating your own classes which do some queries and call them directly, explicitly, without relying on the EntityManagers repository mapping.