In Drupal, if you want to insert something into the node table, ‘nid’ can be null, but ‘vid’ can’t. The inverse is true for the node_revision table.
In which order are nodes inserted when they are created?
I can’t insert into the node table, because I don’t have the revision ID; I can’t insert into the node_revision table, because I don’t have a node ID.
Also, is there some kind of function available that can easily do this insert for you?
The code of the
node_savefunction is available ; did you try to see how it’s working ?Here’s the part that relates to node creation :
Apparently, it first saves the revision of the node, and, only then, saves the node itself.
After that, the node_revisions record is updated, to put the value of the nid.
If you want t save a node, you shouldn’t write code that would do that for you : you just have to call
node_save, and it’ll save the node, call the required hooks, and all that.