Search

1-1 Unidirectional relation Doctrine 2 ORM


Description


use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="product")
 */
class Product {
    /**
     * @ORM\Id @ORM\Column(type="integer") @ORM\GeneratedValue
     * @var int
     */
    private $id;

    /**
     * @ORM\OneToOne(targetEntity="Shipment")
     * @ORM\JoinColumn(name="shipment_id", referencedColumnName="id")
     */
    private $shipment;
}

/**
 * @ORM\Entity
 * @ORM\Table(name="shipment")
 */
class Shipment {
    /**
     * @ORM\Id @ORM\Column(type="integer") @ORM\GeneratedValue
     * @var int
     */
    private $id;
}
The above @JoinColumn is optional as it would default to shipment_id and id anyways.



Table Product

- id: PK, Auto Increment

- shipment_id: Unique, FK Shipment(id)



Table Shipment

- id: PK, Auto Increment
SEE ALSO