Domanda

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.

È stato utile?

Soluzione

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;
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top