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

Cascade persist order #6468

Closed
1ed opened this issue May 24, 2017 · 4 comments
Closed

Cascade persist order #6468

1ed opened this issue May 24, 2017 · 4 comments
Assignees
Milestone

Comments

@1ed
Copy link
Contributor

1ed commented May 24, 2017

I have a problem reproduced by this gist:

https://gist.github.com/1ed/2d9d639854e46100e1e33b9f560ca634 (You can run it with https://github.com/sensiolabs/melody if you want)

This version works:

melody run --no-cache --trust -vvv https://gist.githubusercontent.com/1ed/2d9d639854e46100e1e33b9f560ca634/raw/b4799646726e8ca3171c0475153ec4eb620e2765/doctrine-persist-order.php

This does not work:

melody run --no-cache --trust -vvv https://gist.githubusercontent.com/1ed/2d9d639854e46100e1e33b9f560ca634/raw/b622c5628b0684074436e4f7207368efeb52fccc/doctrine-persist-order.php
PHP Fatal error:  Uncaught PDOException: SQLSTATE[23000]: Integrity constraint violation: 19 NOT NULL constraint failed: Offer.request_id in /tmp/melody/af91efd8dad36b9b9221ff131a21f6571e2d9c20b16e821fe7cf34136042d3ef7/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php:91

The difference is the usage of cascade persist or manual persist.

It has 2 entities Request and Offer. Request has many Offers and one latest offer, the Offer has a Request. Requests can be created without Offers so the latest offer can be null, but Offers can not be created without a Request. I use UUIDs, so all ids are pre-generated by constructor and available before persistence. Despite of this Doctrine thinks it should insert Offer before Request and not using the existing id, simply makes it null (https://github.com/doctrine/doctrine2/blob/v2.5.6/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php#L643-L650) because its not queued for insert at this time. I have to manually call persist on the request before on the offer to make it work. If I remove the $latestOffer property from the Request it also works without problems.

Is there something that controls the order of cascade persist? Do I something wrong or this is a known limitation or a bug?

Thanks!

@lcobucci
Copy link
Member

@1ed commit calculation order has been changed in master to address dependencies in a better way and probably already fixes that, could you check it?

@1ed
Copy link
Contributor Author

1ed commented May 24, 2017

Ohh, great it seems it works in master. Will it be in the next 2.5 release or just in 2.6? Could you please give me a link to the PR or commit? Thanks!

@lcobucci
Copy link
Member

@1ed sure, it's #1570 that fixed #707.

@lcobucci
Copy link
Member

Closing as duplicate.

@Ocramius Ocramius added this to the 2.6.0 milestone Jun 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants