1
votes

I am trying to get a manyToMay bi-directional mapping working on Symfony 3.2.6 / PHP 7.1. I am unable to get the

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

command to run without an error

[Symfony\Component\Debug\Exception\ContextErrorException] Notice: Undefined index: joinTable

Definition is as follows:

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

and

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

If I remove the mappedBy in the Student Entity the SQL will generate using the doctrine:schema:update command. The example at http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/association-mapping.html#owning-and-inverse-side-on-a-manytomany-association shows the joinTable index on the inversedBy entity, and adding the joinTable to this or the mappedBy entity still generates the error Undefined index: joinTable

So, what if anything am I doing wrong? Is this a bug? Any help much appreciated.

Craig

1
Have you deleted / re-created your database? If you had an existing db and then added / modified the structure of these entities, you may have hit a bug in modifying. This can often be fixed by starting over. Obviously you would not want to do this on a production site!! - ehymel
Thanks for the comment. Yes, removed all tables and failure remains. - Craig Rayner

1 Answers

0
votes

I found the issue here. Not a Doctrine problem, but a subscriber I had written to add a table prefix. I have updated the code for the Table Prefix subscriber to correctly capture when the definition is a manyToMany association and to ignore the non-owning side. I am now using the Table Prefix code from the Doctrine Site at http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/cookbook/sql-table-prefixes.html

Craig.