symfony - How do I use more than one repository class in Symfony2? -
i'm building application in symfony 2.2.
i use custom repository class 1 of entities. include this:
@orm\entity(repositoryclass="myapp\mainbundle\entity\categoryrepository")
i want use methods on category entites 2 other repository classes.
@orm\entity(repositoryclass="gedmo\sortable\entity\repository\sortablerepository") @orm\entity(repositoryclass="gedmo\tree\entity\repository\nestedtreerepository")
the entity, however, expects 1 repositoryclass. how can use 3 of these repositories same entity?
i believe, can have 1 repository per entity. have referenced orm\entity(repositoryclass="myapp\mainbundle\entity\categoryrepository")
if must use repositories within repository,
you can entitymanager repositories (if not same) eg: $em2 = whateveristheentity()
now can have proxy methods in categoryrepository methods in repository want use. eg: $em2->getmethodfromem2()
.
note: wouldn't prefer above solution unless there need. rather create service layer has doctrine entity manager dependency injected. service layer connect repositories , collect final result whatever want achieve (to used in controller). way, code cleaner , testable well.
hope helps.
Comments
Post a Comment