An hour of SQL saves several hours of cut-n-paste
by Chris Cooke on Jun.05, 2010, under Uncategorized
I’m busy making a Drupal front-end for MacIDOL to replace the custom pages. The custom pages feature a section where a user can browse for music through a hierarchical genre scheme. In Drupal, I’ve implemented this as a taxonomy for the genres, adding the Term Field module to store the Jamroom genre_id with each taxonomy term.
cStu, a helpful volunteer, created a set of nodes, each of which was tied to a term in the taxonomy, and copied over the descriptions from the custom pages into the nodes.
Last night I discovered I might be able to do without having an actual node for each term, and just use the term pages directly. The problem is, I now needed each of the genre descriptions copied into the term descriptions.
It looked like I was going to have to write cStu and ask if he would take several hours copying all the same stuff he had just copied into a different place on the site. But then I said, “Hey, the descriptions are stored in a database field for the node. Each node maps to just one taxonomy term. Shouldn’t I be able to copy the description from the node table to the term table?”
The answer is YES! An hour of SQL hacking later, this did the trick:
update drupal_term_data as dtd inner join (select tid from drupal_term_data where vid=1) as ldtd on dtd.tid=ldtd.tid inner join drupal_term_node as dtn on ldtd.tid=dtn.tid inner join drupal_node_revisions as dnr on dtn.nid=dnr.nid set description=body;