Doctrine manyToMany定义不工作未定义索引:joinTable

时间:2017-04-05 22:45:24

标签: symfony doctrine-orm

我正在尝试在Symfony 3.2.6 / PHP 7.1上运行manyToMay双向映射。

我无法得到

php bin/console doctrine:schema:update --dump-sql 

命令无错误地运行

  

[Symfony的\元器件\调试\异常\ ContextErrorException]     注意:未定义的索引:joinTable

定义如下:

Busybee\StudentBundle\Entity\Student:
    type: entity
    table: student
    repositoryClass: Busybee\StudentBundle\Repository\StudentRepository
    id:
        id:
            type: integer
            id: true
            generator:
                strategy: AUTO
    fields:
        startAtSchool:
            type: date
    manyToMany:
        enrolments:
            targetEntity: Busybee\StudentBundle\Entity\Enrolment
            mappedBy: students

Busybee\StudentBundle\Entity\Enrolment:
    type: entity
    table: enrolment
    repositoryClass: Busybee\StudentBundle\Repository\EnrolmentRepository
    id:
        id:
            type: integer
            id: true
            generator:
                strategy: AUTO
    fields:
        status:
            type: string
            length: '32'
        lastModified:
            type: datetime
        createdOn:
            type: datetime
    manyToMany:
        students:
            targetEntity: Busybee\StudentBundle\Entity\Student
            inversedBy: enrolments

如果我删除Student Entity中的mappedBy,SQL将使用doctrine:schema:update命令生成。 http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/association-mapping.html#owning-and-inverse-side-on-a-manytomany-association处的示例显示了inversedBy实体上的joinTable索引,并且将joinTable添加到this或mappedBy实体仍然会生成错误Undefined index:joinTable

那么,如果我做错了怎么办?这是一个错误吗?任何帮助非常感谢。

克雷格

1 个答案:

答案 0 :(得分:0)

我在这里发现了这个问题。不是Doctrine问题,而是我编写的添加表前缀的订阅者。我更新了表前缀订阅者的代码,以便在定义是manyToMany关联时正确捕获并忽略非拥有方。我现在正在http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/cookbook/sql-table-prefixes.html

使用Doctrine网站的表格前缀代码

克雷格。