Doctrine Composite Keys Throwing Error

不打扰是莪最后的温柔 提交于 2019-12-24 15:59:15

问题


I am trying to update my schema in doctrine using:

php vendor/bin/doctrine orm:schema-tool:update

But I am getting the error message:

[Doctrine\ORM\Mapping\MappingException]                                      
  Single id is not allowed on composite primary key in entity entities\Events

The events entity looks like this:

<?php
// entities/Events.php

namespace entities;

use Entities\Enities;
use Doctrine\ORM\Mapping;
use Doctrine\ORM\Mapping\Table;

/**
 * @Entity
 * @Table(name="development.events")
 **/
class Events extends Entities {
    /**
     * @var integer
     *
     * @Id
     * @Column(name="id", type="integer")
     * @GeneratedValue(strategy="AUTO")
     */
    protected $event_id;

    /**
     * @var integer
     *
     * @Id
     * @Column(name="app_id", type="integer")
     */
    protected $app_id = 0;

    /**
     * @var string
     * @Column(type="string", length=64)
     */
    protected $post_title;

    public function __construct($event, $app){
        $this->event_id = $event;
        $this->app_id= $app;
    }

}

According to documentation, composite keys are natively supported. http://doctrine-orm.readthedocs.org/projects/doctrine-orm/en/latest/tutorials/composite-primary-keys.html What am I doing wrong?


回答1:


From the docs:

Every entity with a composite key cannot use an id generator other than “ASSIGNED”. That means the ID fields have to have their values set before you call EntityManager#persist($entity).

So remove @GeneratedValue(strategy="AUTO").



来源:https://stackoverflow.com/questions/36017864/doctrine-composite-keys-throwing-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!