I have a problem with an invalid mapping. I keep getting an error with message:
Missing value for primary key course on "Namespace\XXX\Entity\Subject"
The doctrine:schema:validate command returns the following:
[Mapping] FAIL - The entity-class 'Namespace\XXX\Entity\Subject' mapping is invalid: * The join columns of the association 'schedule' have to match to ALL identifier columns of the target entity 'Namespace\XXX\Entity\Subject', however 'id, course, class, day, timeslot' are missing.
This is my mapping:
Subject-entity
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="message", type="string", length=255)
*/
private $message;
/**
* @ORM\ManyToOne(targetEntity="Oggi\ScheduleBundle\Entity\Schedule", inversedBy="subjects")
* @ORM\JoinColumn(name="schedule", referencedColumnName="id")
*/
private $schedule;
/**
* @var \DateTime
*
* @ORM\Column(name="date", type="date")
*/
private $date;
/**
* @var \DateTime
*
* @ORM\Column(name="created", type="datetime")
*/
private $created;
Schedule Entity
/** * @var integer * * @ORM\Column(name="id", type="integer") * @ORM\Id */ private $id;
/**
* @var string
*
* @ORM\Id
* @ORM\OneToOne(targetEntity="Oggi\KlasBundle\Entity\Course")
* @ORM\JoinColumn(name="course", referencedColumnName="id")
*/
private $course;
/**
* @var string
*
* @ORM\Id
* @ORM\ManyToOne(targetEntity="Oggi\KlasBundle\Entity\Klas", inversedBy="schedules")
* @ORM\JoinColumn(name="class", referencedColumnName="id")
*/
private $klas;
/**
* @var string
*
* @ORM\Id
* @ORM\OneToOne(targetEntity="Day")
* @ORM\JoinColumn(name="day", referencedColumnName="id")
*/
private $day;
/**
* @var string
*
* @ORM\Id
* @ORM\OneToOne(targetEntity="Timeslot")
* @ORM\JoinColumn(name="timeslot", referencedColumnName="id")
*/
private $timeslot;
/**
* @ORM\OneToMany(targetEntity="Oggi\CalendarBundle\Entity\Subject", mappedBy="schedule")
*/
private $subjects;
I suppose that what Symfony is telling me to do is include all primary keys in my subject-entity. Is there a way to only include the ID of the schedule in this entity. I had this in mind:
Thanks in advance!
The reason you get this error is because all columns in your
Schedule
entity are marked as anId
.Just remove
@ORM\Id
from all columns but$id
- this should fix the case