Drupal 6 Clinic: Why Does My SQL Preview in Views Look Wrong?
This is more of a post about a Drupal curiousity I discovered the other day than anything but other people may have come across or wondered about the same thing so I thought I\'d just do a quick summary. I was constructing a rather complicated View on a Drupal 6 site using Views 3 the other day and I noticed that not all of the fields seemed to be appearing in the substantial SQL query preview generated by views when a preview of the output is generated.
I wondered if this was something untoward or just a curiousity so I did a very simple test. I set up a minimal Drupal 6 clean installation and created a new view using just a content type filter, with the visible fields being node title and one CCK field. The view worked fine, displaying the expected output, but the query preview only contained information about the node table with the CCK table being nowhere to be seen.
You can see the (very quickly photoshopped) screenshot below which combines the admin screen with the SQL preview. Please click on the image to get the big version which is actually readable.
Curious about this, I wandered into the Views IRC channel on Freenode to see if those more enlightened than myself had the answer. Unsurprisingly they did. The answer is that not all CCK fields will be present in the initial SQL generated by Views - in particular those that require multiple values to be displayed (e.g. a field with a series of checkboxes). There\'s no way for Views to handle this initially so it has to perform extra queries once the initial node information is collated by the view. I did have a suspicion that it was something along these lines, I was just trying to avoid spending hours buried in a PHP debugger to deduce the result.
So if anyone has ever wondered about this, now you know!
A big thank you to Damiankloip and Dawehner from the \"#drupal-views\" IRC channel for their help.
There will be more here from the world of Drupal development when I find something else that I think other people may find useful or may have run into problems with.