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.
Instead of using an entity's primary ID, entity references should use the entity's UUID.
But the change is so huge for Drupal8,
So we can add a choice to use UUID in entity reference values instead of the entity's ID when create a new entity reference field.
It mill make help for
- remote entity reference
- migrations, e.g. #2748609: [meta] Preserving auto-increment IDs on migration is fragile.
...
Comment | File | Size | Author |
---|---|---|---|
#14 | 2874548-14.patch | 8.16 KB | lawxen |
Comments
Comment #2
phenaproxima+1 for this!
I am in favor of swapping the roles of serial IDs and UUIDs. UUIDs should be the canonical IDs, and serial IDs should be more disposable, site-specific identifiers. This might require a hopefully-not-too complex migration path, but I think it'd be worth it. And this would be a good first step.
Comment #3
cosmicdreams CreditAttribution: cosmicdreams commentedThis seems like an all around good thing. If we're going to link back to a thing, it's best to use the id that is guaranteed to always be the unique identifier for that thing.
But, in this issue's description, I was hoping to read some kind of insight as to why this is a good and important change. Seeing how doing this would fundamentally change how referenced entities have behaved for a long time.
Can you please fill out the description with an explanation as to why this change is needed and the primary and secondary impacts of this change?
Comment #4
phenaproximaComment #5
skwashd CreditAttribution: skwashd at Dave Hall Consulting for Pfizer, Inc. commentedDuring the 8.0 development cycle there was a proposal to replace serial IDs with UUIDs in urls and other places. On that issue (#1726734: Replace serial entity IDs with UUIDs in URLs, or even globally?) there was some discussion around performance. I would encourage you to review that issue,
For the record, I would love to see UUIDs everywhere.
Comment #6
DamienMcKennaComment #7
skwashd CreditAttribution: skwashd at Dave Hall Consulting for Pfizer, Inc. commentedComment #8
DamienMcKennaI'd love to see UUIDs usable everywhere, but serial IDs for user-visible paths, e.g. node/123 instead of node/4bd1c937-f530-456f-a218-241d7bfd40b8 (though both could be useful). The point of this issue is that entity reference data is internal, it shouldn't be exposed publicly, so it could IMHO be changed to a UUID structure.
Comment #9
heddnDeleted duplicate comment.
Comment #10
heddnDeleted duplicate comment.
Comment #11
heddn+1
Using uuid for all the things would be wonderful. Baby steps.
Comment #12
DamienMcKennaComment #14
lawxen CreditAttribution: lawxen at Sparkpad commentedFunctional done.
Still needs:
Such as:Change name: target_id to target_uuid.
Comment #15
lawxen CreditAttribution: lawxen at Sparkpad commentedComment #16
hchonovMoving to the field system component.
Review of #14:
We cannot remove the reference by ID until D9 and we should not change the schema as well. Instead we should add an option for new fields, whether they will use reference by ID or reference by UUID - "reference_type", while leaving the reference by ID the default option until D9. This leads to naming the new property "target_uuid". The returned columns and properties then should depend on the setting "reference_type". An entity reference field in D8 will become more complex when conditions in entity queries are build for it, therefore it would be nice if we add explicit API methods for retrieving the reference type e.g. -
EntityReferenceFieldItemListInterface::isReferenceByID()
andEntityReferenceFieldItemListInterface::isReferenceByUUID()
.Comment #17
lawxen CreditAttribution: lawxen at Sparkpad commented@hchonov
Thanks for the advice
I fully agree with your idea, Because the change of #14's hook_update is huge.
Entity's 'type' field, Node's uid, revision_uid fields..... entity_reference exits everywhere, Drupal8 can't bear this kind of changing.
I will do this in the next step, Just allow new field to select the storage mode.
Comment #18
lawxen CreditAttribution: lawxen at Sparkpad commentedComment #20
lawxen CreditAttribution: lawxen at Sparkpad commentedComment #21
mstef CreditAttribution: mstef commentedWould be great to supply a migration for existing fields that want to switch to UUID as well (once this gets done).
Comment #22
Wim LeersAlso relevant to API-First. (Discovered via #2951093-2: Support alphanumeric entity IDs and config entities.)
Comment #26
colanComment #27
lawxen CreditAttribution: lawxen at Sparkpad commentedComment #30
fgmFor the record, this ties in with module @laxwen's Remote Entity Reference, https://www.drupal.org/project/remote_entity_reference
Comment #31
Mykola Dolynskyi+1 for having opportunity to use UUID as primary ID, with migration mechanism, in D9 core