tirenweb
tirenweb

Reputation: 31709

symfony2 and doctrine: in one to many relationship, unique key for foreign keys are assigned

I have this entity:

class Partido
{
/**
 * @ORM\Id
 * @ORM\Column(type="integer")
 * @ORM\GeneratedValue(strategy="AUTO")
 */
protected $id;

/**
 * @ORM\ManyToOne(targetEntity="Project\Bundle\AdminBundle\Entity\Jornada", inversedBy="partidos")
 * @ORM\JoinColumn(name="temporada_id", referencedColumnName="id")
 **/
private $jornada;

/**
 * @ORM\OneToOne(targetEntity="Project\Bundle\AdminBundle\Entity\Equipo")
 * @ORM\JoinColumn(name="equipo1_id", referencedColumnName="id")
 */
private $equipo1;

/**
 * @ORM\OneToOne(targetEntity="Project\Bundle\AdminBundle\Entity\Equipo")
 * @ORM\JoinColumn(name="equipo2_id", referencedColumnName="id")
 */
private $equipo2;

When I generate the database, equipo1 and equipo2 are uniquey keys, why?

CREATE TABLE IF NOT EXISTS `partido` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `temporada_id` int(11) DEFAULT NULL,
  `equipo1_id` int(11) DEFAULT NULL,
  `equipo2_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `UNIQ_4E79750B8D588AD` (`equipo1_id`),
  UNIQUE KEY `UNIQ_4E79750B1A602743` (`equipo2_id`),
  KEY `IDX_4E79750B6E1CF8A8` (`temporada_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=8 ;

I dont want them to be unique keys..

Upvotes: 0

Views: 660

Answers (1)

Amine
Amine

Reputation: 271

your columns join with Equipo entity "ManyToOne":

/**
 * @ORM\ManyToOne(targetEntity="Project\Bundle\AdminBundle\Entity\Equipo")
 * @ORM\JoinColumn(name="equipo1_id", referencedColumnName="id")
 */
 private $equipo1;

/**
 * @ORM\ManyToOne(targetEntity="Project\Bundle\AdminBundle\Entity\Equipo")
 * @ORM\JoinColumn(name="equipo2_id", referencedColumnName="id")
 */
private $equipo2;

Upvotes: 1

Related Questions