Why does my entity need an arbitrary ::getId() method in this scenario? #7129

Closed
opened 2026-01-22 15:45:18 +01:00 by admin · 3 comments
Owner

Originally created by @danielrhodeswarp on GitHub (Apr 11, 2023).

Bug Report

Q A
BC Break no
Version 2.14.1

Summary

I have a "parent" entity (Grouping) which may have zero, one or more "child" entities (GroupingAssociation).
Grouping has a few standard text and date fields.
GroupingAssociation is a polymorphic tracking table and it stores Individuals (another Doctrine entity) and / or Services (another Doctrine entity) that may belong to a Grouping.
One novel thing with the GroupingAssociation entity is that it does not have a single primary identifier column of its own - its primary key is a composite of every field that it has. (And I suspect that this might be the cause of the issue.)

Current behavior

I can only persist() and flush() my Grouping and GroupingAssociation entities if I add an arbitrary getID() method to the GroupingAssociation entity.
If I do not have this arbitrary getID() method - I get this error:

Attempted to call an undefined method named "getId" of class "App\Entity\GroupingAssociation".

How to reproduce

I get the error every time with the following controller method and configuration of entities:

orm_issue_4
orm_issue_1
orm_issue_2
orm_issue_3

Expected behavior

I would not expect to have to insert an arbitrary getId() method into an entity that doesn't have an "id" column, or that doesn't have a single primary key column.

Originally created by @danielrhodeswarp on GitHub (Apr 11, 2023). ### Bug Report <!-- Fill in the relevant information below to help triage your issue. --> | Q | A |------------ | ------ | BC Break | no | Version | 2.14.1 #### Summary <!-- Provide a summary describing the problem you are experiencing. --> I have a "parent" entity (Grouping) which may have zero, one or more "child" entities (GroupingAssociation). Grouping has a few standard text and date fields. GroupingAssociation is a polymorphic tracking table and it stores Individuals (another Doctrine entity) and / or Services (another Doctrine entity) that may belong to a Grouping. One novel thing with the GroupingAssociation entity is that it does not have a single primary identifier column of its own - its primary key is a composite of every field that it has. (And I suspect that this might be the cause of the issue.) #### Current behavior <!-- What is the current (buggy) behavior? --> I can only persist() and flush() my Grouping and GroupingAssociation entities if I add an arbitrary `getID()` method to the GroupingAssociation entity. If I do not have this arbitrary `getID()` method - I get this error: > Attempted to call an undefined method named "getId" of class "App\Entity\GroupingAssociation". #### How to reproduce <!-- Provide steps to reproduce the bug. If possible, also add a code snippet with relevant configuration, entity mappings, DQL etc. Adding a failing Unit or Functional Test would help us a lot - you can submit one in a Pull Request separately, referencing this bug report. --> I get the error every time with the following controller method and configuration of entities: ![orm_issue_4](https://user-images.githubusercontent.com/1181906/231140308-8080786b-bddb-432b-be18-a17bf1a4685d.png) ![orm_issue_1](https://user-images.githubusercontent.com/1181906/231140314-502803d7-22a1-47ab-bc32-23c709f96593.png) ![orm_issue_2](https://user-images.githubusercontent.com/1181906/231140316-7836fe50-d953-4368-84a3-6e0be67b990e.png) ![orm_issue_3](https://user-images.githubusercontent.com/1181906/231140317-c0e52506-878f-43ee-8fe1-7f61237d9fce.png) #### Expected behavior <!-- What was the expected (correct) behavior? --> I would not expect to have to insert an arbitrary `getId()` method into an entity that doesn't have an "id" column, or that doesn't have a single primary key column.
admin closed this issue 2026-01-22 15:45:19 +01:00
Author
Owner

@mpdude commented on GitHub (Apr 12, 2023):

Can you use a debugger to find out when/why/where the code reaches/calls that getId()` method?

Also, I notice you're using the same property as the @Id column and declare it to be an association. I guess this is valid, but at the same time it's a pattern I have seen rarely until today.

@mpdude commented on GitHub (Apr 12, 2023): Can you use a debugger to find out when/why/where the code reaches/calls that getId()` method? Also, I notice you're using the same property as the `@Id` column and declare it to be an association. I guess this is valid, but at the same time it's a pattern I have seen rarely until today.
Author
Owner

@danielrhodeswarp commented on GitHub (Apr 14, 2023):

Thanks @mpdude , yes I think the quirkiness here stems from having such an unusual primary key on my entity.
Debugging - and even just stack tracing - is a great idea that I will look into.
Who knows, this could be an actual bug in Doctrine?

@danielrhodeswarp commented on GitHub (Apr 14, 2023): Thanks @mpdude , yes I think the quirkiness here stems from having such an unusual primary key on my entity. Debugging - and even just stack tracing - is a great idea that I will look into. Who knows, this could be an actual bug in Doctrine?
Author
Owner

@danielrhodeswarp commented on GitHub (Apr 14, 2023):

Ah, OK, well I think we can close this issue as far as it being an issue with Doctrine.
The thing that is trying to call ->getID() is the data-dog/audit-bundle package that I am using.
So either a bug or a mis-configuration with data-dog and nothing sinister with Doctrine :-)

@danielrhodeswarp commented on GitHub (Apr 14, 2023): Ah, OK, well I think we can close this issue as far as it being an issue with Doctrine. The thing that is trying to call ->getID() is the data-dog/audit-bundle package that I am using. So either a bug or a mis-configuration with data-dog and nothing sinister with Doctrine :-)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#7129