cnmicha
cnmicha

Reputation: 172

symfony 2 - Attempted to call an undefined method named "findBy" of class "testBundle\Entity\test"

I can't get data out of the database. Here's the code:

$testRepository= $this->getDoctrine()->getRepository('testBundle:test');
    $potds = $testRepository->findBy(
        array(),
    );

Here's the entity class:

 * @ORM\Table()
 * @ORM\Entity(repositoryClass="testBundle\Entity\test")
 * @ORM\HasLifecycleCallbacks
 */
class test
{ /* ... */ }

Here's the code of the Repository:

namespace testBundle\Entity;

/**
 * TestRepository
 *
 * This class was generated by the Doctrine ORM. Add your own custom
 * repository methods below.
 */
class testRepository extends \Doctrine\ORM\EntityRepository
{
}

I get this error message: symfony 2 - Attempted to call an undefined method named "findBy" of class "testBundle\Entity\test"

Inserting data with Doctrine works, so there should be everything right with the Entity.

Upvotes: 2

Views: 3686

Answers (2)

Kamil Adryjanek
Kamil Adryjanek

Reputation: 3338

You have incorrect repository class definition:

@ORM\Entity(repositoryClass="testBundle\Entity\test")

Should be:

@ORM\Entity(repositoryClass="testBundle\Entity\testRepository")

For now this code:

$testRepository= $this->getDoctrine()->getRepository('testBundle:test');

is returning entity class, not repository.

Upvotes: 6

KhorneHoly
KhorneHoly

Reputation: 4766

Your definition for the repositoryClass is wrong

@ORM\Entity(repositoryClass="testBundle\Entity\test")

doesn't provide the full path and class name.

@ORM\Entity(repositoryClass="testBundle\Entity\testRepository")

you need to provide the full path and class name, so that Symfony is able to get the correct route.

Upvotes: 1

Related Questions