mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
To make assert($mapping instanceof ManyToManyOwningSideMapping) error more explicit
#7493
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @olinox14 on GitHub (Mar 27, 2025).
Feature Request
replacing
4baa7bd252/src/Mapping/AssociationMapping.php (L138)by something like :
Would ease the debugging of this error, as today, the assertion error does not provide any information about the cause of the error.
@greg0ire commented on GitHub (Mar 27, 2025):
Can you send a PR? If you do, read https://github.com/doctrine/orm/issues/11208 to select the right branch.
@greg0ire commented on GitHub (Mar 27, 2025):
Also, maybe it makes sense to do something similar for
4baa7bd252/src/Mapping/AssociationMapping.php (L132)@olinox14 commented on GitHub (Mar 29, 2025):
Done, here is the PR : https://github.com/doctrine/orm/pull/11896
@beberlei commented on GitHub (Mar 29, 2025):
Does this even happen? The assert seems to be to make ststic analysis happy
@olinox14 commented on GitHub (Mar 29, 2025):
@beberlei I'm not sure about the static analysis, but it would certainly be more dev-friendly. In the current state, the dev only receives an AssertionError stating :
with no information about which relation is at fault or why. An explicit exception describing the origin of the problem and suggesting a solution would save time and trouble for the user.
Before :
After :
@greg0ire commented on GitHub (Mar 29, 2025):
@olinox14 given your phrasing, I assumed this happened to you in real life. Is that really the case?
@olinox14 commented on GitHub (Mar 29, 2025):
@greg0ire Yeah, you're right :)
I was upgrading a legacy project, with hundreds of relations, and encountered this assertion error. I had to resort to using xdebug to find the culprit, hence the issue.
@olinox14 commented on GitHub (Mar 29, 2025):
@beberlei Oh right, sorry, I just realized what you meant to say, that these asserts were to quiet phpstan or whatever to complaining. Sorry for the hasty reply. Well, like I was saying previously, you can run into this assertion error if you misplace the JoinTable attribute.
@greg0ire commented on GitHub (Mar 30, 2025):
Maybe you could add a test showing exactly that situation in your PR
@olinox14 commented on GitHub (Mar 31, 2025):
Done, I've added two unit tests for each of the new exceptions, just waiting for the CI to run