Impromer use of db_rewrite_sql causes error
Niels Hackius - October 27, 2009 - 23:11
| Project: | NodeReferrer |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Description
The i18n module hooking into db_rewrite_sql caused an error suggesting 'n.language' wasn't a proper column for the node table. The attached patch fixes this.

#1
#2
Commited, thanx
#3
Are you really sure that l10n need "node" table and not "node2" table?
#4
I reviewed this and my conclusion is: It depends on the expected return value of nodereferrer_referrers_with_translations() - unfortunately this is not documented:
In my opinion it be node if all nodes, including the original one should be returned.
If the original one should be excluded it should be it should be node2.
This behavior is due to the INNER JOIN in the sql clause which imposes the node2 data on the node data.
i18n attaches a query that might look like this (db_rewrite_sql($query) - default usage)
WHERE (n.language = 'en'
OR n.language = ''
OR n.language IS NULL
)
The query I debugged with looks like this (here db_rewrite_sql($query,'node') was chosen)
SELECT node2.nid, node2.vid, node2.title FROM node node INNER JOIN node node2 on node2.tnid = node.tnid WHERE (node.language ='en' OR node.language ='' OR node.language IS NULL) AND ( node.nid IN (105,104,103) AND node.tnid > 0 )#5
Suppose we should filter node by language to return all referrers
#6
Automatically closed -- issue fixed for 2 weeks with no activity.