DDC-774: Getting the primary key of a reference fetches the object from database #955

Open
opened 2026-01-22 12:57:09 +01:00 by admin · 0 comments
Owner

Originally created by @doctrinebot on GitHub (Aug 27, 2010).

Jira issue originally created by user arnaud-lb:

When creating a reference (i.e. $ref = $em->getReference('\Foo', 1);), getting the value of the primary key (i.e. $ref->getId();) fetches the object from the database.

My understanding ot Doctrine is that the references are proxies to real objects, and that calling any method on them will trigger a fetch from the database, which makes sense.

May be this could be improved so that proxies have a check like if (I*am_a_reference() and this_is_a_pkey_getter()) return $pkey). This_is_a_pkey*getter() could get its knowledge from some @PrimaryKeyGetter entity annotation.

The references could then be used in place of the PartialReferences, without the huge WTF-factor of partial references and partial objects.

Originally created by @doctrinebot on GitHub (Aug 27, 2010). Jira issue originally created by user arnaud-lb: When creating a reference (i.e. `$ref = $em->getReference('\Foo', 1);`), getting the value of the primary key (i.e. `$ref->getId();`) fetches the object from the database. My understanding ot Doctrine is that the references are proxies to real objects, and that calling any method on them will trigger a fetch from the database, which makes sense. May be this could be improved so that proxies have a check like `if (I*am_a_reference() and this_is_a_pkey_getter()) return $pkey)`. This_is_a_pkey*getter() could get its knowledge from some @PrimaryKeyGetter entity annotation. The references could then be used in place of the PartialReferences, without the huge WTF-factor of partial references and partial objects.
admin added the Bug label 2026-01-22 12:57:09 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#955