0
votes

In my app I have several custom repositories which are mapped with respective Entity classes and orm.yml files.

They are all defined in the same manner and structure apart of course their names and members.

Yet when I try to get the custom repositories, just for a specific one I get the super class of the repository instead of the correct repository.

$a = $this->em->getRepository('MyAppCommonBundle:Activity'); //doesn't work

$b = $this->em->getRepository('MyAppCommonBundle:Activity:User'); //works

$c= $this->em->getRepository('MyAppCommonBundle:ActivityStatus'); //works

MyAppCommonBundle is defined: MyAppCommonBundle' => 'MyApp\CommonBundle\Entity

$a returns the wrong super class Doctrine\ORM\EntityRepository while $b returns the correct MyApp\CommonBundle\Repository\UserRepository and $c is MyApp\CommonBundle\Repository\ActivityStatus

All Entities are in the same folder MyApp\CommonBundle\Entity. All repositories are in the same place too MyApp\CommonBundle\Repository.

Activity.orm.yml:

MyApp\CommonBundle\Entity\Activity:
    type: entity
    table: activity
    repositoryClass: MyApp\CommonBundle\Repository\ActivityRepository
    indexes:

and for example User.orm.yml:

MyApp\CommonBundle\Entity\User:
    type: entity
    table: user
    repositoryClass: MyApp\CommonBundle\Repository\UserRepository

Activity Repository:

<?php

namespace MyApp\CommonBundle\Repository;

use Doctrine\ORM\EntityRepository; 


class ActivityRepository extends EntityRepository
{

User Repository:

<?php

namespace MyApp\CommonBundle\Repository;

use Doctrine\ORM\EntityRepository; 
class UserRepository extends EntityRepository
...

As stated above, User and other repositories are found, Activity is not...

I tried clearing cache, rebuilding entities with no effect. Obviously tried to look for typos etc. but looks good.

Any idea? Thanks

1
No ORM annotations in your Activity entity? No orm.XML files floating around?Cerad
And check if your repo has the right namespace and the same class name as the filename.Frank B

1 Answers

0
votes

Cerad, there are no ORM annotations that are relevant. Activity entity:

<?php

namespace MyApp\CommonBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * Activity
 *
 * @ORM\Table(name="activity"...)
 * @ORM\Entity
 */
class Activity
{...

User entity:

<?php

namespace MyApp\CommonBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * User
 *
 * @ORM\Table(name="user"...)
 * @ORM\Entity
 */
class User
{
....

There are no orm.xml files at all. And Frank, yes, the repository class names are the same as their file names.