Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does Drupal 6.x Views query multiple taxonomy terms tied to a single piece of content?

This question is about Drupal plumbing. I know how, using the Views query builder, to render multiple taxonomy terms that are associated with a single piece of content. What I can't figure out is how Views actually queries the database to get the job done.

For example, it's easy to have Views show a list of Blog Posts that have one or more tags:

Title: "Brett Favre is Hurt"  
Body: "blah blah blah"  
Tags: Football, Injury  

Title: "Cliff Lee Signs Contract"  
Body: "blah, blah, blah"  
Tags: Baseball, Free Agency, Philadelphia  

What I can't seem to figure out is how Views goes about pulling the multiple tags and rendering them with each content item. The Views Preview query doesn't show any such SQL involving the taxonomy.

My guess is that a subquery of sorts is going on at the Taxonomy "field" or the query pulls multiple records and somehow groups the fields at title and body (which would seem rather inefficient).

I'm doing my best to follow Drupal standard practices for a custom module, and I'd like to know how the Drupal Views folks run these queries since they run pretty fast.

like image 550
Randy Burgess Avatar asked Nov 05 '22 05:11

Randy Burgess


1 Answers

It is doing it in the pre_render() function, with a separate query, see views 2 api documentation.

When trying to figure out how Views is doing X, I always try to figure out in which handler this happens. Since all of them are separated into classes in separate files (usually below the modules/module_name folder)

like image 94
Berdir Avatar answered Nov 11 '22 03:11

Berdir