WTF: How can I find out what information is available in the node table?

Submitted by Marc on Fri, 11/22/2013 - 2:04pm

What's that File (layout)?

There are many different ways to figure out what information the node table contains.

  1. You could use dsm($node); in an appropriate place in your code, assuming you have the Devel module installed.
  2. You could also use a poor man's version of dsm, a la drupal_set_message('<pre>' . print_r($node, 1) . '</pre>');.
  3. You might think to take a look at the Node template file.
  4. On the other hand, you might ssh into a server and do something like mysql -u someuser --database=somedatabase -p followed by DESC node. Some of you might even have done drush sqlc instead of entering the mysql sequence.

But, most of those options would require you to leave your browser. And maybe the node.tpl.php doesn't quite make things clear for you. How about looking at the code that defines the table?

Some of you may be saying, "But then I'd still have to go out to a terminal and do a drush dl drupal." Alas, there is another way to approach looking at code, that I use quite regularly. I'll walk you through the steps for this particular example.

  1. Navigate to the project page.
  2. Look in the right sidebar and click on the View commits link.
  3. Click on any of the commit ids
  4. Strip out part of the path to take you to the project git repo. Of course, if you remember the pattern [I never do], you can just go directly to the repo without all those extra clicks.
  5. Scroll down the page to the section that says "heads."
  6. Choose one of the heads and click on the tree link.
  7. Next click on the modules link.
  8. Select node.
  9. Open up node.install and look at function node_schema().

While this post focused strictly on finding out the schema for the node table, the technique could be used to find out anything about what a project is doing, without having to leave your browser. In addition, it makes mention of a lot of other handy tools.

You may be wondering:

  • "What is this devel module and what is dsm?"
  • "What is drupal_set_message and what if I can't interrupt the program flow to print a message to the screen at that time?"
  • "What is the Node template file and when would I use it?"
  • "What is this drush sqlc and drush dl?"

All of those questions make for more blog posts!

If you'd like to read a post on one of those topics, or on some other topic, register an account (sorry commenting is still disabled for anonymous visitors) and leave a comment or shoot me a message through my contact form.

Thanks to Chris Miller for suggesting that I write this post.