开发者

How do I set a MySQL field to be the dynamically generated value of another field?

开发者 https://www.devze.com 2023-01-22 03:22 出处:网络
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 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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消