3

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

BispensGipsGebis
  • 399
  • 6
  • 13
  • Can you tell us if there's something special beneath the last DocBlock? Like an extended class? Or where the error is thrown exactly (which line triggers it)? Because at first sight, I'm looking over the issue. – UrGuardian4ngel Jul 20 '13 at 19:38
  • The query is throwing the error. According to the log it is the getResult() that throws it. – BispensGipsGebis Jul 21 '13 at 08:22

2 Answers2

11

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

BispensGipsGebis
  • 399
  • 6
  • 13
0

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

Florent
  • 12,310
  • 10
  • 49
  • 58
Cerad
  • 48,157
  • 8
  • 90
  • 92
  • Well, don't think this is THE issue. I initially thought the same, so I tried it with my classes. Surprisingly, it worked...? Edit: Well, using entity on entity, not entity on ID as stated here, but still. – UrGuardian4ngel Jul 20 '13 at 19:34
  • I have read up on the query builder. I have a many-to-many relationship broken into three tables (and corresponding) classes. So I need to control how the joins are made. Doing what you propose Cerad gives the wrong result. @UrGuardianAngel et.tag is the id-field in the ET class so it corresponds to ID which is the ID field for the Tag class. Would it be any help if I enclosed the three classes: Tag, Entity, EntityTag? – BispensGipsGebis Jul 21 '13 at 08:27