Doctrine composite primary key as well as foregin keys

512 views Asked by At

i have a table which has two columns that are foreign keys from another two tables. I would like to make them composite primary key together as well as foreign key each one. Here is my Entity from symfony;

/**
 * ilan_emlakOzellik
 *
 * @ORM\Table()
 * @ORM\Entity
 */
class ilan_emlakOzellik
{

/**
 * @ORM\Id
 * @ORM\Column(type="integer")
 * @ORM\ManyToOne(targetEntity="ilan")
 * @ORM\JoinColumn(name="ilanId")
 */
private $ilanId;

/**
 * @ORM\Id
 * @ORM\ManyToOne(targetEntity="emlakOzellik")
 * @ORM\JoinColumn(name="ozellikId")
 * @ORM\Column(type="integer")
 */
private $ozellikId;

After the write this schema to db, i see primary keys but foreign keys are missing. How can i make them foreign key too? Thanks for helping.

1

There are 1 answers

0
Ocramius On BEST ANSWER

Validate your schema - these mappings are incorrect. Either a field is a column, or it is an association. Having both mappings on the same field is not allowed:

/**
 * ilan_emlakOzellik
 *
 * @ORM\Table()
 * @ORM\Entity
 */
class ilan_emlakOzellik
{

    /**
     * @ORM\Id
     * @ORM\ManyToOne(targetEntity="ilan")
     * @ORM\JoinColumn(name="ilanId")
     */
    private $ilanId;

    /**
     * @ORM\Id
     * @ORM\ManyToOne(targetEntity="emlakOzellik")
     * @ORM\JoinColumn(name="ozellikId")
     */
    private $ozellikId;