Julien Leray
Julien Leray

Reputation: 1687

Entity Repository Method not found

I've some trouble with an method Repository. I want to find all user from city (address) from province form the state. I thought it's was good to divide all request method in Repository for more reusability. I call :

$addr_repo = $this->getEntityManager()
                 ->getRepository('BtpUserProBundle:Address');
$address[$key] = $addr_repo->findByProvince($province->getId());

and my method findByProvince:

namespace Btp\UserProBundle\Repository;

use Doctrine\ORM\EntityRepository;

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

public function findByProvince($province_id)
{
    var_dump("lol");
    $ret = $this->getEntityManager()
        ->createQuery('SELECT a FROM Btp\UserProBundle\Entity\Address a JOIN a.province p WHERE p.id = :val')
        ->setParameter('val', $province_id)
        ->getResult();        

    var_dump($ret);     
    return $ret;
}

Address:

* @ORM\Table(name="address")
* @ORM\Entity(repositoryClass="Btp\UserProBundle\Repository\AddressRepository")
* @ORM\Entity
*/
class Address {//somethink}

"lol" is not display. But I haven't any error. Another question; do you think it's bad practice to use Repository in another Repository (conceptually speaking)

Thanks

Upvotes: 0

Views: 689

Answers (1)

ponciste
ponciste

Reputation: 2229

as mentioned in my comment, you should remove the second @ORM\Entity in your Address class declaration

* @ORM\Table(name="address")
* @ORM\Entity(repositoryClass="Btp\UserProBundle\Repository\AddressRepository")
* @ORM\Entity <---- remove this
*/

Upvotes: 2

Related Questions