HOWTO: Views 2 Relationships
After getting sick of closing issues in various module's issue queues that boiled down to people not knowing how to use Views 2's relationship feature I decided to make a screencast explaining it:
http://drewish.blip.tv/file/1593750/
I think I need to get a microphone, and figure out all the features of the tool I was using but I'm excited to do more of these.
Update: The GotDrupal folks have a much more detailed—and more understandable—screencast on this topic: http://gotdrupal.com/videos/drupal-views-relationships
Sorting numeric values stored in character fields with views.module
I spent a good chunk of time this morning trying to figure out how to get the views module to sort a character field with numeric data correctly. The audio module has a normalized table of meta-data meaning that there's one column for the tag name and one for the value. The value is stored as a character string which causes problem when sorting numeric data like the track numbers or years. If you've got a SELECT value FROM audio_metadata ORDER BY value that returns the range of numbers 1...13 it ends up sorted as 1,10,11,12,13,2,3...9. The trick as I discovered is to add zero to the field to coerce it to a numeric value: SELECT value + 0 AS v FROM audio_metadata ORDER BY v.
The problem then is to figure out how to get the views module to generate this bit SQL to get the sorting right. The solution I came upon is when defining the field set 'notafield' to TRUE and provide a 'query_handler' to generate the correct SQL. I've included the relevant parts of the audio module below to demonstrate how it works. You can see the complete code here.