tags:

views:

53

answers:

2

I'm mucking around with drupal, and it has two fields called nid and vid on its node table. Every record I look at seems to have the same value for both nid and vid.

I'm hacking around and inserting nodes the non-drupal way, and I want to make sure vid is set to whatever value nid has.

For sake of explanation, here's something that I'd hope for:

INSERT INTO node (vid, type, blah, blah) VALUES (value_of(nid), "webpage", "blah", "blah");

value_of doesn't exist of course, but hopefully you get the idea of what I'm looking for.

+1  A: 

You are missing some vital understanding.

  • {node} holds info about each node, the pk and serial is the nid (node id), the vid is a reference to the {node_revisions} table.
  • {node_revisions} holds info about the body field of a node. Here vid is the pk and serial while it also has a nid which is a reference to the {node} table.

One node can have multiple revisions. This makes it possible to save old versions of the same node. If you never make a new revision to a node, the nid and vid will be the same, but for each new revision that's made, the vid will increase while the nid stays the same.

So in short, nid and vid shouldn't be equal, but in some cases they are. You should you the {node_revisions} to get the vid for your insert to the {node} table.

googletorp
Thanks. I'm writing a simple dev/production sync script, and with your information I just updated it to grab each node_revision as well as each node.
Blaine LaFreniere
A: 

You can use nodefactory module to create new node. It doesn't brake drupal db structure and creates nodes with all necessary fields filled. Then you can use even cck fields. This is right way to create nodes from your code.

Denis Shishkov