mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Improve MappingException message #6149
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 @BonBonSlick on GitHub (Dec 29, 2018).
Feature Request
Summary
I have spent some time to figure out why this exception was thrown because mapping files and calsses exist. Hard to track why and where(what mapping) exception was thrown.
thrown in
dump output
As you can see
<embedded name="id" class="App\Domain\AnimePack\Episode\ValueObject\EpisodeId" use-column-prefix="false" />Is mapped, class loaded, it is ok, but where id comes from? Why?
It really took a while, error logged this message, not much useful info.
I tried to remove mapping files which we have a lot, and find out that problem was in realtions mappings where we miss join column
was
must be
As I figured out:
1 - join column was required
2 - because of embedded ids referenced-column-name must be uuid.
It would be nice to throw exception with correct message that join column is missing for specified mapping.
EG
Error message and common, widespread used field ID confused a lot.
Thanks.
@Ocramius commented on GitHub (Jan 2, 2019):
Could you make ab example of what is triggering the error? You've shown how it manifests, but not the userland code that leads to it.
If this is an attempt to use an
@Embeddableas part of an@Id, I don't think that it ever worked before, not was implemented at all.@BonBonSlick commented on GitHub (Jan 2, 2019):
Relation mapping triggering error. I should add join column, and UUID to reference not ID. UUID it is @Embeddable $id with parameter $uuid as you can see. But for other not relation @Embeddable fields we set name as it is $name and it is @Embeddable class.
@Ocramius commented on GitHub (Jan 2, 2019):
@BonBonSlick that didn't come through very clear: can you please elaborate/rewrite that?
@BonBonSlick commented on GitHub (Jan 2, 2019):
2 entities, User and UserRole. xml mapping used.
Both of them has parameter $id which are
@Embeddable.This
@Embeddableclasses has own parameters $uuid.Example UserId (
@Embeddablepoints toUser::$id)User @Embeddable $id
Same has UserRole, UserRoleId.
Now, when we set up relation mapping with xml, by default
referenced-column-nameis ID<join-column name="user_role"="uuid" /> // default reference column is UserRole::$idTo make it work we have to add
<join-column name="details_uuid" referenced-column-name="uuid" /> // not ID but UUIDWe reference to
@Embeddableclass parameter, no original, related class. Referenced notUserRole::$idbut toUserRoleId::$uuidparameter.Exception says here that ID does not exists, which confusing.
@Ocramius commented on GitHub (Jan 2, 2019):
All
<join-column/>must reference identifiers though. Also, embeddable fields as identifiers are not really supported, as mentioned above.@BonBonSlick commented on GitHub (Jan 6, 2019):
But question is about improving exception message, I got it already
And made it work as it should be. Just letting you know that exception message was confusing. Someone else may run in the same situation. Maybe add or highlight such case in docs in relation mapping section would be nice.