BispensGipsGebis
BispensGipsGebis

Reputation: 409

Symfony/Doctrine: Class is not a valid entity or mapped super class

I'm getting the "Class PriceOrQuality\POQBundle\Entity\Tag is not a valid entity or mapped super class error. I've have checked all the answers to similar questions, but I cannot seem to grasp the problem.

The error is thrown by my Repository Class

<?php

namespace PriceOrQuality\POQBundle\Entity\Repository;

use Doctrine\ORM\EntityRepository as ER;
use PriceOrQuality\POQBundle\Entity\Tag;
use Doctrine\ORM\EntityManager;

/**
 * EntityTagsRepository
 *
 */
class EntityTagsRepository extends ER
{
    public function getTagsForTagCloud($entity_ids = null, $tag_id = null) {

        $em = $this->getEntityManager();

        $qb = $em->createQueryBuilder();
        $qb->select(array('IDENTITY(et.tag) as id, COUNT(et.tag) as tag_id_count, LOWER(t.tag) as tag'));
        $qb->from('PriceOrQuality\POQBundle\Entity\EntityTag', 'et');
        $qb->leftjoin('PriceOrQuality\POQBundle\Entity\Tag','t', 'WITH', 'et.tag = t.id');
        $qb->groupBy('et.tag');
        $qb->addOrderBy('tag_id_count','DESC');
        $qb->setMaxResults(20);      
        return $qb->getQuery()
                ->getResult();
    }
}

The Tag class is defined in this file (Tag.php) (definition only):

<?php

namespace PriceOrQuality\POQBundle\Entity;

// src/PriceOrQuality/POQBundle/Entity/Tag.php

use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use PriceOrQuality\POQBundle\Entity\EntityTag;
use PriceOrQuality\POQBundle\Entity\User;
use JMS\SerializerBundle\Serializer\Serializer;

/**
 * @ORM\Entity(repositoryClass="PriceOrQuality\POQBundle\Entity\Repository\TagsRepository")
 * @ORM\Table(name="tags")
 * @ORM\HasLifecycleCallbacks 
 */

Does any of you smart guys have any idea on where to start with the debugging?

Thanks in advance,

Rune

Upvotes: 3

Views: 9618

Answers (2)

Cerad
Cerad

Reputation: 48865

Read up a bit on query builder. It's easier and different than a sql query. No need for join conditions.

This (for starters):

$qb->leftjoin('PriceOrQuality\POQBundle\Entity\Tag','t', 'WITH', 'et.tag = t.id');

Should just be:

$qb->leftJoin('et.tag','t');

There might be more problems but that will get you started. http://docs.doctrine-project.org/en/latest/reference/query-builder.html

Upvotes: 0

BispensGipsGebis
BispensGipsGebis

Reputation: 409

Found the issue.

I had a //@todo after the meta definition and before the class definition. Apparently that screwed up the mapping, as it was not mapped in doctrine.

Moving the //@todo and rerunning the mapping fixed the problem.

For whomever finds this question with similar problems try running:

php app/console doctrine:mapping:info

It will show you if you have problems in the mapping structure in doctrine

Thanks for your time guys.

Cheers, Rune

Upvotes: 12

Related Questions