Foreign key references

Created on 4 June 2010, about 14 years ago
Updated 1 October 2023, 9 months ago

Nice work on this project! I'm digging into building an install profile using profiler to supplement what we don't get yet with features and I like what I see.

One thing I'd like to look at is references between items to be created. (This question is an issue in Features too.) Take for example users and nodes. Currently the code hard-codes UID values in creating a user and then in providing the UID of a node. This works, but isn't very robust. For example, it would break if another process first added a user.

We already have for each object a good identifier--the key it was given in the array where it was declared. For example, in profiler_example.profiler.inc, the 'superduper' user is explicitly assigned an ID, but could instead be identified as 'superduper'. I'd see this working as follows:

* user array remains the same except doesn't have the [uid] key.
* node array remains the same but in place of [uid] has:

nodes[front][_reference][property] = uid
nodes[front][_reference][type] = user
nodes[front][_referende][item] = superduper

To handle this we would need:

* track all objects that have been created in a static variable, noting the IDs that were assigned. E.g., for the superduper user, this would be:

$items['users']['superduper'] = 1;

* Iterate through all references, passing the array item by reference. If the references are already set, add their ID value to the passed array item, using the 'property'. E.g.,

nodes[front][_reference][property] = uid
nodes[front][_reference][type] = user
nodes[front][_reference][item] = superduper

becomes

nodes[front][uid] = 1

If they are not set, create the item and then set the ID property.

In some cases we would need to return a modified version of the ID value. For example, it should be possible to point menu items to specific nodes. For this:

menu-items[front][_reference][property] = link_path
menu-items[front][_reference][prefix] = node/
menu-items[front][_reference][type] = node
menu-items[front][_reference][item] = mynode
✨ Feature request
Status

Needs work

Version

2.0

Component

Code

Created by

πŸ‡¨πŸ‡¦Canada nedjo

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024