-
-
Notifications
You must be signed in to change notification settings - Fork 87
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
Creating entities with One2One and One2Many relationships fails if one2one is before one2many #835
Comments
hey @mmarton cool thanks for the reproducer, I'll have a look soon did this happen in a recent version? |
yes, everything is on the latest version.
edit: I misunderstood the question. The issue was introduced with the 2.3.0 version. |
An extra addition to the issue: If I move my one2one relation as the last entry of the array and call ProductFactory::new()->withOptionalEntity['optionalentity' => OptionalEntityFactory::new()])->create() to add a new optional relation that is not present in the default() array, then the same issue happens. |
hey @mmarton out of curiosity, do you use php 8.4? For some reasons, I'm struggling to fix this in every possible combinations of "cascade persist" relationships. I think the only real complete fix will use php 8.4 proxy objects |
Interesting. Yes the project is already on 8.4, like the reproducer I've created |
just found a very nice workaround :) I'd be glad if you try this before we merge. I've already tested it in your reproducer, and everything works. |
I've tested your fix, and interestingly it fixes my reproducer, but fails in my project with the same thing: it tries to save an incomplete entity. I have no idea why. |
😬 |
I don't manage to reproduce it within our testsuite without a reproducer 😞 this problem may occur because we're flushing an extra time before, the flush of the "root" factory. Can you check if you're passing several times here although only one call to |
thanks for your help. Here is my trace, I hope it helps something:
|
Good day @nikophil !
You've helped me before with my edge cases about one2one relationships in the past (#655), and I'm here again with a special case. :)
There is this special case that happens in the PersistentObjectFactory with one2one relations:
foundry/src/Persistence/PersistentObjectFactory.php
Line 310 in 719710a
If my entity has a one2one and a many2one this "placeholder entity" may be flushed by doctrine.
This happens when the one2one relation is defined before the one2many, making the order of keys in the default function matter.
I've created a small reproducer to this issue:
https://github.com/mmarton/foundry-entity-relations-issue
best to you
The text was updated successfully, but these errors were encountered: