Skip to content

Table already exists error if there is intermediate entity for many-to-many relationship #102

@rela589n

Description

@rela589n

I get next error when try to do pa doctrine:schema:update

The table with name 'new_ads_doctrine.proposals' already exists.
at vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/SchemaException.php:112

Customer:

<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
                          https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
    <entity name="App\Entities\Customer" table="customers">
        <id name="uuid" type="string" column="id">
            <generator strategy="NONE"/>
        </id>

        <embedded name="email" class="App\ValueObjects\Email" use-column-prefix="false"/>
        <embedded name="password" class="App\ValueObjects\Password" use-column-prefix="false"/>

        <one-to-many field="postedJobs" target-entity="App\Entities\Job" mapped-by="customer"/>
    </entity>
</doctrine-mapping>

Freelancer:

<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
                          https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
    <entity name="App\Entities\Freelancer" table="freelancer">
        <id name="uuid" type="string" column="id">
            <generator strategy="NONE"/>
        </id>

        <embedded name="email" class="App\ValueObjects\Email" use-column-prefix="false"/>
        <embedded name="password" class="App\ValueObjects\Password" use-column-prefix="false"/>
        <embedded name="hourRate" class="App\ValueObjects\Money" use-column-prefix="false"/>

        <one-to-many field="proposals" target-entity="App\Entities\Proposal" mapped-by="freelancer"/>
    </entity>
</doctrine-mapping>

Job:

<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
                          https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
    <entity name="App\Entities\Job" table="jobs">
        <id name="uuid" type="string" column="id">
            <generator strategy="NONE"/>
        </id>

        <embedded name="title" class="App\ValueObjects\JobTitle" use-column-prefix="false"/>
        <embedded name="description" class="App\ValueObjects\JobDescription" use-column-prefix="false"/>

        <many-to-one field="customer" target-entity="App\Entities\Customer" inversed-by="postedJobs"/>
        <one-to-many field="proposals" target-entity="App\Entities\Proposal" mapped-by="job"/>

        <many-to-many field="freelancersApplied" target-entity="App\Entities\Freelancer">
            <join-table name="proposals">
                <join-columns>
                    <join-column name="job_id"/>
                </join-columns>
                <inverse-join-columns>
                    <join-column name="freelancer_id"/>
                </inverse-join-columns>
            </join-table>
        </many-to-many>
    </entity>
</doctrine-mapping>

Proposal:

<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
                          https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
    <entity name="App\Entities\Proposal" table="proposals">
        <id name="uuid" type="string" column="id">
            <generator strategy="NONE"/>
        </id>

        <embedded name="coverLetter" class="App\ValueObjects\CoverLetter" use-column-prefix="false"/>
        <embedded name="estimatedTime" class="App\ValueObjects\EstimatedTime" use-column-prefix="false"/>

        <many-to-one field="job" target-entity="App\Entities\Job" inversed-by="proposals"/>
        <many-to-one field="freelancer" target-entity="App\Entities\Freelancer" inversed-by="proposals"/>
    </entity>
</doctrine-mapping>

Or is there way to explicitly define intermediate entity for many-to-many relationship?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions