Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
All entities currently have an id of some kind, but it's called all different things for all different entity types, and entities of different entity types can even have the same id. This means that if you've got a list of entity ids, you also need the corresponding entity types in order to use them.
Could we have an index table that just contains the global entity id ($eid ?), the entity type, and the local entity id?
Comments
Comment #1
Dave ReidSounds like you want a UUID. :)
Comment #2
DamienMcKenna.. or just a generic $entity->id to go along with the equally generic $entity->type? Or be verbose if you must by having $entity->entity_type and $entity->entity_id.
Comment #3
Dave ReidYou can always reliably get the ID using entity_extract_ids().
Comment #4
naught101 CreditAttribution: naught101 commentedOnly if you know the type.
UUID - yep, more or less, but just drupal-install-wide, not universal.
Comment #5
fagoI think we want to add an easy id accessor to our entity class, e.g.
$entity->identifier()
. As done in #1184944: Make entities classed objects, introduce CRUD support. Maybe the shorther$entity->id()
would b even better?Comment #6
damiankloip CreditAttribution: damiankloip commentedThis type of problem has come up for me a few times too. Maybe the fruits of entity_extract_ids work should always be present when entities are loaded, and integrated in somehow.
Comment #7
catchWe should consider enforcing id as the actual key - if you don't use it as a column name (or have entities that don't exist in the db) it could still be handled by the controller, would save adding the getter. Either way would be preferable to entity_extract_ids() though.
Comment #8
casey CreditAttribution: casey commentedThis is what I made out of it: http://drupal.org/project/entity_index
Comment #9
fago>We should consider enforcing id as the actual key - if you don't use it as a column name (or have entities that don't exist in the db) it could still be handled by the controller, would save adding the getter.
I like that idea, however wouldn't it mean there is no
$node->nid
any more?Comment #10
colanThe work being done over at Proposing a 2.x branch (generic entity solution) [for UUID] is relevant here.
Comment #11
sun#1637370: Add UUID support to core entity types