-
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
Fetching entities with Composite Key Relations and null values #11486
Fetching entities with Composite Key Relations and null values #11486
Conversation
e2f3e93
to
bcc7c62
Compare
This would definitely help with some of our use cases. 👍 |
Does this affect 3.x only? If not, you should target 2.19.x and then we merge this up. |
I assume this will wait until the 2.19 branch gets upmerged before the work of this PR can proceed |
Here we go: #11525 |
@greg0ire thanks a lot! 🎉 Sorry for asking but any ETA when it will be actually released? Thanks 🙏🏻 |
No worries, but why did you close this? Did I maybe cover everything you wanted to do in my merge up? I can publish a release when that's cleared up. |
@greg0ire thank you - yes, correct - your merge up from 2.19.x covered this completely PR completely (the fix was exactly the same in 2.19.x as it is here, just the difference with annotations->attributes in tests). Just checked, and the only difference (between this and your merge up) was importing the models in tests: Thanks again! 🙌 |
Recreation of #8425 as it was closed but never actually resolved and the issues still persist.
Description from the previous PR (Background):
In our database design we are using entities with composite keys, and we are using composite keys relations between entities.
Let say we have the following entities with Primary Keys (PK):
Company
(PK:company_code
)Customer
(PK composite:company_code
+customer_code
)Invoice
(PK composite:company_code
+invoice_code
)and the following relations in
Invoice
:Company
(usingcompany_code
), not nullableCustomer
(using composite keycompany_code
+customer_code
), nullableNow we have
company_code
(not null) but nocustomer_code
(null).We want to fetch
Invoice
entity, so that we get not nullCompany
, and nullCustomer
.The problem is that loading
Invoice
with nullCustomer
is not working - we are getting the following exception:This PR provide a fix, to load the
Customer
in the described case.The change is pretty simply, and no other tests are affected.
NOTE: Loading
Company
is not a problem as it is using relation on just one column (not a composite key). The description includes it just for completeness of the example.Workaround
We have discovered that we could use one of these workarounds - but both are not perfect:
Solution
The solution proposed in this PR is very minimal - just removal od one of the condition, which seems to be not covered, and I couldn't find track why it has been even added there. Based on the example provided in this PR, the removed condition seems to be invalid.
PR contains two commits:
Additional considerations
The following comment confused me a lot:
orm/src/UnitOfWork.php
Line 2456 in 9d4f54b
and I did additional investigation if the proposed solution here is correct.
In the below we are removing just first part of the condition:
orm/src/UnitOfWork.php
Lines 2470 to 2476 in 9d4f54b
and I was wonder if the target entity could/should know if it is a part of a FK somewhere else - and I can't even see the reason behind that, so I believe this is the correct fix as it is the case when the filed "is part of target's entity primary key".
Hope it all makes sense and we can get it in. Thanks 🙌