I thought that ids (user id, node id, ...) are strictly sequential which ensures that later added content has always higher id that a previously added one. So that when I have a hierarchy (lower element has a reference to its parent) and the 'reference' is not editable (set on creation) I can safely assume that a child has higher id that a parent.

The problem is that in this question @berdir (who I believe knows a few things about Drupal) says that it does not have to be the case...

I know that gaps might appear in the sequence (e.g. when an entity is deleted) but I'm not sure that he meant just that (and I'd rather be sure).

So my question is, how is in reality and when can I not the sentimentality of ids?

//DISC: The hierarchy system is quite complex and (of course) doesn't rely on ids comparison, the aforementioned concept is used just in one case due to optimization.


User IDs and Node IDs are automatically incrementing (mysql, postgresql, sqlite) fields. Once an id has been used, it should not be used again (in the case of deleted content).

The higher the number, the later it was inserted into the database.

You could always end up with imported content that is older, but now has a higher Node/User ID because it was inserted at a later time.

You may want to look to the Relation module, or even Drupal's own menu system to define hierarchies. This depends completely on your use case of course.

  • I'll definitely look at relation module (though I doubt it will make my tree-like-hierarchies simpler than they're now). Considering the menu system, how would suggest implementing a tree-like-hierarchy for entities with it (I just can't think of any way)?
    – Petrroll
    May 10 '14 at 0:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.