Symfony2 Doctrine2 ManyToMany Composite key Column name referenced does not exist

Viewed 3238

I have a ManyToMany relation with a composite key on the reverse side. When I use the console command doctrine:schema:update I have the following error:

[Doctrine\ORM\ORMException]
Column name `keyword` referenced for relation from Map\MapBundle\Entity\
Student towards Map\MapBundle\Entity\SkillType does not exist.

I have an entity student (unique key) with a ManyToMany relation with an entity skill (composite key) which has a ManyToOne relation with skillType (unique key).

Here is the different class mapping I have:

Class Student

<?php
namespace Map\MapBundle\Entity;
use Doctrine\ORM\Mapping as ORM;

/**
 * Student
 *
 * @ORM\Table()
 * @ORM\Entity(repositoryClass="Map\MapBundle\Entity\StudentRepository")
 */
class Student {
    /**
     *
     * @var integer @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @ORM\ManyToMany(targetEntity="Map\MapBundle\Entity\SkillType")
     * @ORM\JoinTable(name="students_skills",
     *      joinColumns={
     *      @ORM\JoinColumn(name="keyword", referencedColumnName="keyword"), 
     *      @ORM\JoinColumn(name="attribut", referencedColumnName="attribut")
     * })
     */
    private $skills;
}

Class skill

<?php
namespace Map\MapBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
 * Skill
 *
 * @ORM\Table()
 * @ORM\Entity(repositoryClass="Map\MapBundle\Entity\SkillRepository")
 */
class Skill {
    /**
     * @ORM\ManyToOne(targetEntity="Map\MapBundle\Entity\skillType")
     * @ORM\JoinColumn(name="keyword", referencedColumnName="keyword")
     * @ORM\Id
     */
private $keyword;
}

Classe skillType

<?php
namespace Map\MapBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
 * SkillType
 *
 * @ORM\Table()
 * @ORM\Entity(repositoryClass="Map\MapBundle\Entity\SkillTypeRepository")
 */
class SkillType {
    /**
     * @var string
     *
     * @ORM\Column(name="keyword", type="string", length=255)
     * @ORM\Id
     */
    private $keyword;
}

I tried to exchange the keyword and attribut @joinColumn lines, but I have the same error message with attribut instead of keyword.

I can't see what's wrong with my mapping. The table skill exists and has columns named keyword and attribut.

I hope that somebody will see where I made a mistake (probably a typo error like a missing character or a case mistake).

2 Answers
Related