Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TopologicalSorter still breaks purge with foreign key constraints #329

Open
videni opened this issue Nov 25, 2019 · 1 comment
Open

TopologicalSorter still breaks purge with foreign key constraints #329

videni opened this issue Nov 25, 2019 · 1 comment
Labels

Comments

@videni
Copy link

videni commented Nov 25, 2019

I have this issue today at doctrine/data-fixtures v1.3.2 , what I did wrong?

Order.orm.xml

<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xmlns:gedmo="http://gediminasm.org/schemas/orm/doctrine-extensions-mapping"
                  xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
                                      http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">

    <entity name="Acme\Bundle\OrderBundle\Entity\Order" table="acme_order">
        <id name="id" column="id" type="integer">
            <generator strategy="AUTO" />
        </id>
        <one-to-one field="review" target-entity="Acme\Bundle\ReviewBundle\Entity\OrderReview" mapped-by="reviewSubject"/>
        <one-to-one field="report" target-entity="Acme\Bundle\ReportBundle\Entity\Report" mapped-by="order"/>
    </entity>
</doctrine-mapping>

OrderReview.orm.xmln

<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping">
    <entity name="Acme\Bundle\ReviewBundle\Entity\OrderReview" table="acme_order_review">
     <id name="id" column="id" type="integer">
            <generator strategy="AUTO" />
        </id>
        <one-to-one field="reviewSubject" inversed-by="review" target-entity="Acme\Bundle\OrderBundle\Entity\Order"/>
    </entity>
</doctrine-mapping>

Report.orm.xml

<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
                  xmlns:gedmo="http://gediminasm.org/schemas/orm/doctrine-extensions-mapping"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
                                      http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">

    <entity name="Acme\Bundle\ReportBundle\Entity\Report" table="acme_auto_report"  >
        <id name="id" column="id" type="integer">
            <generator strategy="AUTO" />
        </id>

        <one-to-one field="order" inversed-by="report" target-entity="Acme\Bundle\OrderBundle\Entity\Order" />
       
    </entity>

</doctrine-mapping>

the the result table orders are following, but acme_auto_report table hold foreign key to acme_order, it must be before the acme_order table like acme_order_review table.

26 => "acme_order_review"
  27 => "acme_order"
  34 => "acme_auto_report"

Originally posted by @videni in #230 (comment)

@videni
Copy link
Author

videni commented Nov 25, 2019

what quite strange is the error will disapear if call the sort method twice.
ORMPurger

 private function getCommitOrder(EntityManagerInterface $em, array $classes)
    {
        $sorter = new TopologicalSorter();

         //....
        $sorter->sort();  // call sort method twice.

        return array_reverse($sorter->sort());
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants