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

Dave Reid’s picture

Sounds like you want a UUID. :)

DamienMcKenna’s picture

.. 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.

Dave Reid’s picture

You can always reliably get the ID using entity_extract_ids().

naught101’s picture

Only if you know the type.

UUID - yep, more or less, but just drupal-install-wide, not universal.

fago’s picture

I 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?

damiankloip’s picture

This 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.

catch’s picture

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. Either way would be preferable to entity_extract_ids() though.

casey’s picture

This is what I made out of it: http://drupal.org/project/entity_index

fago’s picture

>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?

colan’s picture

The work being done over at Proposing a 2.x branch (generic entity solution) [for UUID] is relevant here.

sun’s picture

Status: Active » Closed (duplicate)