-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Persisting entities with OneToOne and OneToMany/ManyToOne relationship between them. #6499
Comments
@triasinformatica-gabe could you check if this issue happens on |
@lcobucci I will check this later today and get back to you with the findings. Thansk for the reply. |
@triasinformatica-gabe awesome! Please keep in mind that dependencies versions for |
@lcobucci I've just tested the minimal example against In order to help pinpoint the issue I've created a repository with the minimal example (Symfony 2.8.*, DoctrineBundle, Doctrine and PHPUnit). I added the example entities A and B mentioned above as well as two simple PHPUnit tests indicating the problematic scenario. Setting it up would be a matter of running the following commands, given you have a database connection set-up: > composer install
> php app/console doctrine:schema:update --force
> phpunit -c app/ If there's anything else I can do to contribute to this, please let me know. |
@triasinformatica-gabe what would really helps us is a PR with that failing test. Could you please send it? You can find examples on https://github.com/doctrine/doctrine2/tree/388afb46d0cb3ed0c51332e8df0de9e942c2690b/tests/Doctrine/Tests/ORM/Functional/Ticket |
@lcobucci Sure, I'll look into it. |
… of what happened at persistence-level
…r makes it *SOMEWHAT* more readable (no miracles)
The patch related to this was reverted, as foreign key integrity issues occur when dealing with deletes. This needs additional testing and inspection. |
…-nullable cascading relationship
…-nullable cascading relationship
…-nullable cascading relationship
…-nullable cascading relationship
…-nullable cascading relationship
…-nullable cascading relationship
…bug on non-nullable cascading relationship
…bug on non-nullable cascading relationship
…bug on non-nullable cascading relationship
…-nullable cascading relationship
…bug on non-nullable cascading relationship
…-nullable cascading relationship
…bug on non-nullable cascading relationship
…-nullable cascading relationship
…bug on non-nullable cascading relationship
…-nullable cascading relationship
…bug on non-nullable cascading relationship
…-nullable cascading relationship
…bug on non-nullable cascading relationship
@Frikkle was the first to propose these tests in doctrine#6533. @rvanlaak followed up in doctrine#8703, making some adjustments.
@Frikkle was the first to propose these tests in doctrine#6533. @rvanlaak followed up in doctrine#8703, making some adjustments. Co-authored-by: Gabe van der Weijde <[email protected]> Co-authored-by: Richard van Laak <[email protected]> Co-authored-by: Grégoire Paris <[email protected]>
Add tests to show #6499 has been fixed
Last week I encountered an issue in one of our projects where we had two entities, call them A and B having a unidirectional OneToOne A->B (with the join column not nullable) and a OneToMany(A->B)/ManyToOne(B->A) bidirectional relationship between them.
The problem lies in the order of persisting them; when first persisting A, then B, a constraint violation is thrown: SQLSTATE[23000]: Integrity constraint violation: 19 NOT NULL constraint failed: a.b_id, indicating that the join column isn't allowed to be NULL, even though it should have been set.
I reworked my code to a minimal example:
Entity A
Entity B
My persist code
The code above throws the constraint violation error. At first I thought it might be related to circular cascade persists. But if I remove all cascade annotation and the orphanRemoval clauses as well, it still throws the ConstraintViolationException.
What does work?
It does however seem to work when I revert the persist order, like this:
And, it also works when wrapping the whole operation in a transaction. But somehow I have the feeling that it should work.
Possibly related issues
When looking through the issue list I came across #4090 which seems to be a similar issue. Maybe this helps to shine light on that as well?
Our environment
We're working in Symfony 2.8 LTS using the
doctrine/doctrine-bundle
version1.6.4
anddoctrine/orm
version2.5.5
. After upgradring both of them to the latest version, the problem persisted.The text was updated successfully, but these errors were encountered: