Say I have an Offer, which can have 1-n Range. Immediately you think, "put a offer_id inside Range".
But my Offer has a composite primary key (composed of two fields). There is no AUTOINCREMENT id column.
The Doctrine2 documentation doesn't say much about that particular case, here is my entities:
<?php
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Table()
* @ORM\Entity
*/
class Offer
{
/**
* @var Site $site
* @ORM\Id
* @ORM\ManyToOne(targetEntity="Site")
* @ORM\JoinColumn(name="site_id", referencedColumnName="id")
*/
private $site;
/**
* @var string $pouet
* @ORM\Id
* @ORM\Column(name="pouet", type="string", length=255)
*/
private $pouet;
}
<?php
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Table(name="RangeItem")
* @ORM\Entity
*/
class Range
{
/**
* @todo This is test code only do not push me :-)
* @var ArrayCollection
* @ORM\ManyToOne(targetEntity="Offer")
*/
private $offers;
}
I obtaind this error:
[Doctrine\ORM\ORMException]
Column nameidreferenced for relation from Pouet\MyBundle\Entity\Range towards Pouet\MyBundle\Entity\Offer does not exist.
That make sense, but how can I deal with this issue? Is a Table with composite primary key forbidden to have associations on it?