Occurs if the {term_node} has a 'weight' column. If a developer adds a 'weight' column to the {term_node} table, the following warning (or similar) will show on certain pages.

user warning: Column 'weight' in order clause is ambiguous query: SELECT t.tid, t.name FROM master_term_data t INNER JOIN master_term_node r ON r.tid = t.tid WHERE t.vid = 7 AND r.nid = 84549 ORDER BY weight LIMIT 0, 1 in /var/www/example.com/sites/all/modules/contrib/pathauto/pathauto.module on line 115.

The fix is easy. Simply change 'ORDER BY weight' to 'ORDER BY t.weight' on line 115 of pathauto.module.

CommentFileSizeAuthor
#3 pathauto-534818.patch1.24 KBmdevrel

Comments

greggles’s picture

Why would a developer add that column?

That said, we probably should use table prefixes on all columns just to be safe.

mdevrel’s picture

In our case, we are using taxonomy terms as image galleries. The weight is used to keep track and enable re-ordering of the images within each gallery. Each image node can belong to more than one gallery, so term_node becomes the logical table to add the weight field since term_node is already used in the query to get the images for a gallery. Simply add term_node.weight to the order-by clause:

SELECT * FROM {node} n LEFT JOIN {term_node} tn
ON n.vid = tn.vid
WHERE tn.tid = %d
ORDER BY tn.weight ASC

Regardless, as you mentioned, it is best-practice to use table prefixes on all columns in any query pulling from more than one table.

mdevrel’s picture

Version: 6.x-1.1 » 7.x-1.x-dev
Assigned: Unassigned » mdevrel
Status: Active » Needs review
StatusFileSize
new1.24 KB

Here's a patch that should fix the issue.

dave reid’s picture

Side note, having the alias 'r' for the {term_node} table is very wonky. Can we do {term_node} tn so this is less ambiguous?

dave reid’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.