-1

I have spent the last few hours trying to find an answer however not gaining at all. I feel that it will end up being something simple that I did not have knowledge of. This section of code is of course incorrect but I wanted to show the idea of what I was trying to do here. I currently have a base repository class that has the findAllQueryBuilder method within it that will allow for reduced code. Right now I have about 10 repository classes that all need to use findAllQueryBuilder. This function is within the basecontroller I have built. The main issue is that this controllor does not see findAllQueryBuilder because as you can see this takes in the parameters to determine which data location is needed. I've done this once already in another location in my code with an interface however that was with a class I will put that example here also.

public function listAction(Request $request, RepositoryTypeInterface $repositoryName, $table, $sql, $route)
{
    $filter = $request->query->get('filter');
    $repository = "Bundle:$repositoryName";
    $qb = $this->getDoctrine()
        ->getRepository($repository, 'tenant')
        ->findAllQueryBuilder($filter, $table, $sql);

As you can see in the following I set the type as the interface to make sure it knew that it was going to be that then.

public function newAction(Request $request, EntityTypeInterface $controllerType, formType, $repository, $routeName)
{

And then instantiated it within the childclass controllor

public function newAction(Request $request, EntityTypeInterface $controllerType = null, $formType = ContactType::class, $repository = 'Contact', $routeName = 'api_contacts_show')
{
    $controllerType = new Contact();
    return parent::newAction($request, $controllerType, $formType, $repository, $routeName);
}

So The first example above has me attempting the same thing however I am not sure how to apply this to this situation. as "Bundle:$repository" is a string and the parameter used is a string and it's not an entity so creating an instance doesn't make sense when all I need is its functionality. I just need some way to have access to this functionality. any ideas would work but I'm feeling like I'm missing something simple.

Here is the exact error I get, Method 'findAllQueryBuilder' not found in \Doctrine\Common\Persistence\ObjectRepository Referenced method is not found in subject class.

I'm sure there is a way to apply this concept to fix the lack of 'seeing' the function however as of right now I'm not completely sure. Thank you anyone in advance.

EDIT: I'm using a basecontrollor that is setting this up for the other controllers ie:cantactscontrollor class which uses the ContactEntity class mapped to the contactrepository class which is a child of a baserepository class which is where findAllQueryBuilder is located, I'm not sure how to map that.

  • 1
    Looks like doctrine thinks `\Doctrine\Common\Persistence\ObjectRepository` is the repository of your class, did you set the repository to your custom class in the class mapping? – ccKep Jun 16 '17 at 15:31
  • check Edit for a little more detail on file structure – Ken Echard Jun 16 '17 at 16:53
  • Hi! I'm not sure there inheritance is a problem when it comes to repository classes, just make sure you have @Entity(repositoryClass="") in your ContactEntity annotation, assuming you use annotations. – SebastianGreen Jun 16 '17 at 17:08
  • please add more information about your entity and repository classes. – lordrhodos Jun 17 '17 at 05:51
  • I've solved the issue. It simply require a docblock for it to know that it was of a type I'll post my code as an answer. – Ken Echard Jun 19 '17 at 14:53

1 Answers1

0
public function listAction(Request $request, $repositoryName, $table, $sql, $route)
{
    $filter = $request->query->get('filter');
    $repository = "TenantBundle:$repositoryName";

    /** @var RepositoryTypeInterface $qb */
    $qb = $this->getDoctrine()
        ->getRepository($repository, 'tenant');

    $queryResults = $qb->findAllQueryBuilder($filter, $table, $sql);

Sorry for the late response on this but here is the answer I was able to find. As I thought it was a simple thing but essentially the Docblock labeled $qb as the said interface above making sure it knew that any class that implements it will be accepted. Now knowing what type it will be, the error message is no longer there. Notice also how I split it up.